Skip to content

Commit

Permalink
Fix #1223
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 25, 2016
1 parent 1e5d349 commit fe32b96
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ Tom Mack (tommack@github)
the requested value type
(2.7.4)

William Headrick (headw01@github)
* Reported#1223: `BasicClassIntrospector.forSerialization(...).findProperties` should
respect MapperFeature.AUTO_DETECT_GETTERS/SETTERS?
(2.7.5)

Nick Babcock (nickbabcock)
* Reported #1225: `JsonMappingException` should override getProcessor()
(2.7.5)
Expand Down
3 changes: 3 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Project: jackson-databind

2.7.5 (not yet released)

#1223: `BasicClassIntrospector.forSerialization(...).findProperties` should
respect MapperFeature.AUTO_DETECT_GETTERS/SETTERS?
(reported by William H)
#1225: `JsonMappingException` should override getProcessor()
(reported by Nick B)
#1228: @JsonAnySetter does not deserialize null to Deserializer's NullValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,12 @@ public VisibilityChecker<?> getDefaultVisibilityChecker()
if (!isEnabled(MapperFeature.AUTO_DETECT_CREATORS)) {
vchecker = vchecker.withCreatorVisibility(Visibility.NONE);
}
if (!isEnabled(MapperFeature.AUTO_DETECT_GETTERS)) {
vchecker = vchecker.withGetterVisibility(Visibility.NONE);
}
if (!isEnabled(MapperFeature.AUTO_DETECT_IS_GETTERS)) {
vchecker = vchecker.withIsGetterVisibility(Visibility.NONE);
}
if (!isEnabled(MapperFeature.AUTO_DETECT_FIELDS)) {
vchecker = vchecker.withFieldVisibility(Visibility.NONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,16 @@ public BeanDescription introspectDirectClassAnnotations(JavaType type) {
public VisibilityChecker<?> getDefaultVisibilityChecker()
{
VisibilityChecker<?> vchecker = super.getDefaultVisibilityChecker();
// then global overrides (disabling)
if (!isEnabled(MapperFeature.AUTO_DETECT_SETTERS)) {
vchecker = vchecker.withSetterVisibility(Visibility.NONE);
}
if (!isEnabled(MapperFeature.AUTO_DETECT_CREATORS)) {
vchecker = vchecker.withCreatorVisibility(Visibility.NONE);
}
if (!isEnabled(MapperFeature.AUTO_DETECT_GETTERS)) {
vchecker = vchecker.withGetterVisibility(Visibility.NONE);
}
// then global overrides (disabling)
if (!isEnabled(MapperFeature.AUTO_DETECT_IS_GETTERS)) {
vchecker = vchecker.withIsGetterVisibility(Visibility.NONE);
}
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/com/fasterxml/jackson/databind/ser/TestFeatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;

Expand Down Expand Up @@ -266,4 +267,37 @@ public void testSingleElementCollections() throws IOException
assertEquals(quote("foo"), writer.writeValueAsString(new String[] { "foo" }));

}

static class TCls {
@JsonProperty("groupname")
private String groupname;

public void setName(String str) {
this.groupname = str;
}
public String getName() {
return groupname;
}
}

public void testVisibilityFeatures() throws Exception
{
ObjectMapper om = new ObjectMapper();
// Only use explicitly specified values to be serialized/deserialized (i.e., JSONProperty).
om.configure(MapperFeature.AUTO_DETECT_FIELDS, false);
om.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
om.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
om.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
om.configure(MapperFeature.USE_GETTERS_AS_SETTERS, false);
om.configure(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
om.configure(MapperFeature.INFER_PROPERTY_MUTATORS, false);
om.configure(MapperFeature.USE_ANNOTATIONS, true);

JavaType javaType = om.getTypeFactory().constructType(TCls.class);
BeanDescription desc = (BeanDescription) om.getSerializationConfig().introspect(javaType);
List<BeanPropertyDefinition> props = desc.findProperties();
if (props.size() != 1) {
fail("Should find 1 property, not "+props.size()+"; properties = "+props);
}
}
}

0 comments on commit fe32b96

Please sign in to comment.