Skip to content

Commit fe32b96

Browse files
committed
Fix #1223
1 parent 1e5d349 commit fe32b96

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

release-notes/CREDITS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ Tom Mack (tommack@github)
447447
the requested value type
448448
(2.7.4)
449449

450+
William Headrick (headw01@github)
451+
* Reported#1223: `BasicClassIntrospector.forSerialization(...).findProperties` should
452+
respect MapperFeature.AUTO_DETECT_GETTERS/SETTERS?
453+
(2.7.5)
454+
450455
Nick Babcock (nickbabcock)
451456
* Reported #1225: `JsonMappingException` should override getProcessor()
452457
(2.7.5)

release-notes/VERSION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Project: jackson-databind
66

77
2.7.5 (not yet released)
88

9+
#1223: `BasicClassIntrospector.forSerialization(...).findProperties` should
10+
respect MapperFeature.AUTO_DETECT_GETTERS/SETTERS?
11+
(reported by William H)
912
#1225: `JsonMappingException` should override getProcessor()
1013
(reported by Nick B)
1114
#1228: @JsonAnySetter does not deserialize null to Deserializer's NullValue

src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,12 @@ public VisibilityChecker<?> getDefaultVisibilityChecker()
777777
if (!isEnabled(MapperFeature.AUTO_DETECT_CREATORS)) {
778778
vchecker = vchecker.withCreatorVisibility(Visibility.NONE);
779779
}
780+
if (!isEnabled(MapperFeature.AUTO_DETECT_GETTERS)) {
781+
vchecker = vchecker.withGetterVisibility(Visibility.NONE);
782+
}
783+
if (!isEnabled(MapperFeature.AUTO_DETECT_IS_GETTERS)) {
784+
vchecker = vchecker.withIsGetterVisibility(Visibility.NONE);
785+
}
780786
if (!isEnabled(MapperFeature.AUTO_DETECT_FIELDS)) {
781787
vchecker = vchecker.withFieldVisibility(Visibility.NONE);
782788
}

src/main/java/com/fasterxml/jackson/databind/SerializationConfig.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,10 +861,16 @@ public BeanDescription introspectDirectClassAnnotations(JavaType type) {
861861
public VisibilityChecker<?> getDefaultVisibilityChecker()
862862
{
863863
VisibilityChecker<?> vchecker = super.getDefaultVisibilityChecker();
864+
// then global overrides (disabling)
865+
if (!isEnabled(MapperFeature.AUTO_DETECT_SETTERS)) {
866+
vchecker = vchecker.withSetterVisibility(Visibility.NONE);
867+
}
868+
if (!isEnabled(MapperFeature.AUTO_DETECT_CREATORS)) {
869+
vchecker = vchecker.withCreatorVisibility(Visibility.NONE);
870+
}
864871
if (!isEnabled(MapperFeature.AUTO_DETECT_GETTERS)) {
865872
vchecker = vchecker.withGetterVisibility(Visibility.NONE);
866873
}
867-
// then global overrides (disabling)
868874
if (!isEnabled(MapperFeature.AUTO_DETECT_IS_GETTERS)) {
869875
vchecker = vchecker.withIsGetterVisibility(Visibility.NONE);
870876
}

src/test/java/com/fasterxml/jackson/databind/ser/TestFeatures.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.fasterxml.jackson.core.JsonGenerator;
77
import com.fasterxml.jackson.databind.*;
8+
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
89
import com.fasterxml.jackson.annotation.*;
910
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
1011

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

268269
}
270+
271+
static class TCls {
272+
@JsonProperty("groupname")
273+
private String groupname;
274+
275+
public void setName(String str) {
276+
this.groupname = str;
277+
}
278+
public String getName() {
279+
return groupname;
280+
}
281+
}
282+
283+
public void testVisibilityFeatures() throws Exception
284+
{
285+
ObjectMapper om = new ObjectMapper();
286+
// Only use explicitly specified values to be serialized/deserialized (i.e., JSONProperty).
287+
om.configure(MapperFeature.AUTO_DETECT_FIELDS, false);
288+
om.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
289+
om.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
290+
om.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
291+
om.configure(MapperFeature.USE_GETTERS_AS_SETTERS, false);
292+
om.configure(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
293+
om.configure(MapperFeature.INFER_PROPERTY_MUTATORS, false);
294+
om.configure(MapperFeature.USE_ANNOTATIONS, true);
295+
296+
JavaType javaType = om.getTypeFactory().constructType(TCls.class);
297+
BeanDescription desc = (BeanDescription) om.getSerializationConfig().introspect(javaType);
298+
List<BeanPropertyDefinition> props = desc.findProperties();
299+
if (props.size() != 1) {
300+
fail("Should find 1 property, not "+props.size()+"; properties = "+props);
301+
}
302+
}
269303
}

0 commit comments

Comments
 (0)