Skip to content

Commit 9a11fb9

Browse files
committed
Backport #541 fix in 2.4 (for 2.4.3)
1 parent 2e8cf4f commit 9a11fb9

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Version: 2.4.3 (xx-xxx-2014)
55
(reported by Ian B, tea-dragon@github)
66
#524: @JsonIdentityReference(alwaysAsId = true) Custom resolver is reset to SimpleObjectIdResolver
77
(reported by pkokorev@github)
8+
#541: @JsonProperty in @JsonCreator is conflicting with POJOs getters/attributes
9+
(reported by fabienrenaud@github)
810
#543: Problem resolving self-referential generic types
911
- Fixed a problem with `acceptJsonFormatVisitor` with Collection/array types that
1012
are marked with `@JsonValue`; could cause NPE in JSON Schema generator module.

src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,11 @@ private void _explode(Collection<PropertyName> newNames,
870870
for (Linked<?> node = accessors; node != null; node = node.next) {
871871
PropertyName name = node.name;
872872
if (!node.isNameExplicit || name == null) { // no explicit name -- problem!
873+
// [Issue#541] ... but only as long as it's visible
874+
if (!node.isVisible) {
875+
continue;
876+
}
877+
873878
throw new IllegalStateException("Conflicting/ambiguous property name definitions (implicit name '"
874879
+_name+"'): found multiple explicit names: "
875880
+newNames+", but also implicit accessor: "+node);

src/test/java/com/fasterxml/jackson/databind/introspect/TestPropertyConflicts.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.fasterxml.jackson.databind.introspect;
22

3+
import com.fasterxml.jackson.annotation.*;
4+
35
import com.fasterxml.jackson.core.JsonProcessingException;
6+
47
import com.fasterxml.jackson.databind.*;
58

69
/**
@@ -62,6 +65,21 @@ public void _stuff(String value) {
6265
}
6366
}
6467

68+
// For [Issue#541]
69+
static class Bean541 {
70+
protected String str;
71+
72+
@JsonCreator
73+
public Bean541(@JsonProperty("str") String str) {
74+
this.str = str;
75+
}
76+
77+
@JsonProperty("s")
78+
public String getStr() {
79+
return str;
80+
}
81+
}
82+
6583
/*
6684
/**********************************************************
6785
/* Test methods
@@ -110,4 +128,23 @@ public void testInferredNameConflictsWithSetters() throws Exception
110128
Infernal inf = mapper.readValue(aposToQuotes("{'stuff':'Bob'}"), Infernal.class);
111129
assertNotNull(inf);
112130
}
131+
132+
public void testIssue541() throws Exception {
133+
final ObjectMapper mapper = new ObjectMapper();
134+
mapper.disable(
135+
MapperFeature.AUTO_DETECT_CREATORS,
136+
MapperFeature.AUTO_DETECT_FIELDS,
137+
MapperFeature.AUTO_DETECT_GETTERS,
138+
MapperFeature.AUTO_DETECT_IS_GETTERS,
139+
MapperFeature.AUTO_DETECT_SETTERS,
140+
MapperFeature.USE_GETTERS_AS_SETTERS
141+
);
142+
Bean541 data = mapper.readValue("{\"str\":\"the string\"}", Bean541.class);
143+
if (data == null) {
144+
throw new IllegalStateException("data is null");
145+
}
146+
if (!"the string".equals(data.getStr())) {
147+
throw new IllegalStateException("bad value for data.str");
148+
}
149+
}
113150
}

0 commit comments

Comments
 (0)