Skip to content

Commit f920a16

Browse files
committed
Fix #2979 as suggested by PR (manual merge)
1 parent a2e914c commit f920a16

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

release-notes/CREDITS-2.x

+6-2
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,13 @@ Halil İbrahim Şener (hisener@github)
12851285
(2.12.1)
12861286
12871287
Faron Dutton (fdutton@github)
1288-
12891288
* Contributed fix for #2990: Breaking API change in `BasicClassIntrospector` (2.12.0)
12901289
(2.12.1)
12911290
1292-
--- END ---
1291+
SunYiJun (xiaosunzhu@github)
12931292
1293+
* Reported, suggested fix for #2979: Conflicting in POJOPropertiesCollector when
1294+
having namingStrategy
1295+
(2.12.1)
1296+
1297+
--- END ---

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Project: jackson-databind
1515
(reported by zigzago@github)
1616
#2978: Fix failing `double` JsonCreators in jackson 2.12.0
1717
(contributed by Carter K)
18+
#2979: Conflicting in POJOPropertiesCollector when having namingStrategy
19+
(reported, fix suggested by SunYiJun)
1820
#2990: Breaking API change in `BasicClassIntrospector` (2.12.0)
1921
(reported, fix contributed by Faron D)
2022

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -446,18 +446,19 @@ protected void collectAll()
446446
property.mergeAnnotations(_forSerialization);
447447
}
448448

449-
// And use custom naming strategy, if applicable...
450-
PropertyNamingStrategy naming = _findNamingStrategy();
451-
if (naming != null) {
452-
_renameUsing(props, naming);
453-
}
454-
455449
// Sort by visibility (explicit over implicit); drop all but first of member
456450
// type (getter, setter etc) if there is visibility difference
457451
for (POJOPropertyBuilder property : props.values()) {
458452
property.trimByVisibility();
459453
}
460454

455+
// And use custom naming strategy, if applicable...
456+
// As per [databind#2979], should be AFTER trimming
457+
PropertyNamingStrategy naming = _findNamingStrategy();
458+
if (naming != null) {
459+
_renameUsing(props, naming);
460+
}
461+
461462
// and, if required, apply wrapper name: note, MUST be done after
462463
// annotations are merged.
463464
if (_config.isEnabled(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME)) {
@@ -1051,9 +1052,8 @@ protected void _renameUsing(Map<String, POJOPropertyBuilder> propMap,
10511052
} else if (prop.hasField()) {
10521053
rename = naming.nameForField(_config, prop.getField(), fullName.getSimpleName());
10531054
} else if (prop.hasGetter()) {
1054-
/* Plus, when getter-as-setter is used, need to convert that too..
1055-
* (should we verify that's enabled? For now, assume it's ok always)
1056-
*/
1055+
// Plus, when getter-as-setter is used, need to convert that too..
1056+
// (should we verify that's enabled? For now, assume it's ok always)
10571057
rename = naming.nameForGetterMethod(_config, prop.getGetter(), fullName.getSimpleName());
10581058
}
10591059
}

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

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.databind.introspect;
22

3+
import com.fasterxml.jackson.annotation.JsonSetter;
34
import com.fasterxml.jackson.databind.*;
45

56
// mostly for [databind#1033]
@@ -15,18 +16,44 @@ public void setValue(Issue1033Bean foo) {
1516
}
1617
}
1718

19+
// [databind#2979]
20+
static class DuplicateSetterBean2979 {
21+
Object value;
22+
23+
public void setBloop(Boolean bloop) {
24+
throw new Error("Wrong setter!");
25+
}
26+
27+
@JsonSetter
28+
public void setBloop(Object bloop) {
29+
value = bloop;
30+
}
31+
}
32+
1833
/*
1934
/**********************************************************
2035
/* Test methods
2136
/**********************************************************
2237
*/
2338

24-
private final ObjectMapper MAPPER = objectMapper();
39+
private final ObjectMapper MAPPER = newJsonMapper();
2540

41+
// [databind#1033]
2642
public void testSetterPriority() throws Exception
2743
{
28-
Issue1033Bean bean = MAPPER.readValue(aposToQuotes("{'value':42}"),
44+
Issue1033Bean bean = MAPPER.readValue(a2q("{'value':42}"),
2945
Issue1033Bean.class);
3046
assertEquals(42, bean.value);
3147
}
48+
49+
// [databind#2979]
50+
public void testConflictingSetters() throws Exception
51+
{
52+
ObjectMapper mapper = jsonMapperBuilder()
53+
.propertyNamingStrategy(PropertyNamingStrategies.LOWER_CAMEL_CASE)
54+
.build();
55+
DuplicateSetterBean2979 result = mapper.readValue(a2q("{'bloop':true}"),
56+
DuplicateSetterBean2979.class);
57+
assertEquals(Boolean.TRUE, result.value);
58+
}
3259
}

0 commit comments

Comments
 (0)