diff --git a/release-notes/CREDITS b/release-notes/CREDITS index 03d738feff..4cbc30c9e7 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS @@ -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) diff --git a/release-notes/VERSION b/release-notes/VERSION index 4a13993264..b47bba5ed0 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -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 diff --git a/src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java b/src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java index e01b7dda75..58487eb039 100644 --- a/src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java +++ b/src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java @@ -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); } diff --git a/src/main/java/com/fasterxml/jackson/databind/SerializationConfig.java b/src/main/java/com/fasterxml/jackson/databind/SerializationConfig.java index 28aea9bc0a..bf0c3f08b6 100644 --- a/src/main/java/com/fasterxml/jackson/databind/SerializationConfig.java +++ b/src/main/java/com/fasterxml/jackson/databind/SerializationConfig.java @@ -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); } diff --git a/src/test/java/com/fasterxml/jackson/databind/ser/TestFeatures.java b/src/test/java/com/fasterxml/jackson/databind/ser/TestFeatures.java index 272edd45bb..3a6e15181e 100644 --- a/src/test/java/com/fasterxml/jackson/databind/ser/TestFeatures.java +++ b/src/test/java/com/fasterxml/jackson/databind/ser/TestFeatures.java @@ -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; @@ -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 props = desc.findProperties(); + if (props.size() != 1) { + fail("Should find 1 property, not "+props.size()+"; properties = "+props); + } + } }