Skip to content

Commit

Permalink
Implemented #269
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 26, 2013
1 parent 8bdd49b commit 105c58a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ New minor version.
(suggested by mckamey@github)
#253: `DelegatingDeserializer` causes problems for Managed/BackReferences
(reported by bfelaco@github)
#269: Add support for new `@JsonPropertyDescription` via `AnnotationIntrospector`
as well as `BeanProperty.getMedata().getDescription()`
[JACKSON-890]: Support managed/back-references for polymorphic (abstract) types
- Add 'BeanPropertyWriter.isUnwrapping()' for future needs (by Afterburner)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,23 @@ public Boolean withMember(AnnotatedMember member) {

@Override
public PropertyMetadata getMetadata() {
return PropertyMetadata.construct(_isRequired(), _findDescription());
final Boolean b = _findRequired();
final String desc = _findDescription();
if (b == null) {
return (desc == null) ? PropertyMetadata.STD_REQUIRED_OR_OPTIONAL
: PropertyMetadata.STD_REQUIRED_OR_OPTIONAL.withDescription(desc);
}
return PropertyMetadata.construct(b.booleanValue(), _findDescription());
}

protected boolean _isRequired() {
protected Boolean _findRequired() {
Boolean b = fromMemberAnnotations(new WithMember<Boolean>() {
@Override
public Boolean withMember(AnnotatedMember member) {
return _annotationIntrospector.hasRequiredMarker(member);
}
});
return (b != null) && b.booleanValue();
return b;
}

protected String _findDescription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ public String getName() {
return (String) additionalProperties.get("name");
}
}

static class PropDescBean
{
public final static String A_DESC = "That's A!";

@JsonPropertyDescription(A_DESC)
public String a;

protected int b;

public String getA() { return a; }

public void setA(String a) { this.a = a; }

@JsonProperty(required=true)
public int getB() { return b; }
}

/*
/**********************************************************
Expand Down Expand Up @@ -390,11 +407,44 @@ public void testJackson703() throws Exception

public void testJackson744() throws Exception
{
BasicBeanDescription beanDesc = mapper.getDeserializationConfig().introspect(mapper.constructType(Issue744Bean.class));
BeanDescription beanDesc = mapper.getDeserializationConfig().introspect(mapper.constructType(Issue744Bean.class));
assertNotNull(beanDesc);
AnnotatedMethod setter = beanDesc.findAnySetter();
assertNotNull(setter);
}

// [Issue#269]: Support new @JsonPropertyDescription
public void testPropertyDesc() throws Exception
{
// start via deser
BeanDescription beanDesc = mapper.getDeserializationConfig().introspect(mapper.constructType(PropDescBean.class));
_verifyPropertyDesc(beanDesc);
// and then via ser:
beanDesc = mapper.getSerializationConfig().introspect(mapper.constructType(PropDescBean.class));
_verifyPropertyDesc(beanDesc);
}

private void _verifyPropertyDesc(BeanDescription beanDesc)
{
assertNotNull(beanDesc);
List<BeanPropertyDefinition> props = beanDesc.findProperties();
assertEquals(2, props.size());
for (BeanPropertyDefinition prop : props) {
String name = prop.getName();
final PropertyMetadata md = prop.getMetadata();
if ("a".equals(name)) {
assertFalse(md.isRequired());
assertNull(md.getRequired());
assertEquals(PropDescBean.A_DESC, md.getDescription());
} else if ("b".equals(name)) {
assertTrue(md.isRequired());
assertEquals(Boolean.TRUE, md.getRequired());
assertNull(md.getDescription());
} else {
fail("Unrecognized property '"+name+"'");
}
}
}

/*
/**********************************************************
Expand Down

0 comments on commit 105c58a

Please sign in to comment.