Skip to content

Commit 8c346ad

Browse files
committed
Fix #3368
1 parent 1eaaa8b commit 8c346ad

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Project: jackson-databind
88

99
#3344: `Set.of()` (Java 9) cannot be deserialized with polymorphic handling
1010
(reported by Sam K)
11+
#3368: `SnakeCaseStrategy` causes unexpected `MismatchedInputException` during
12+
deserialization
13+
(reported by sszuev@github)
1114
#3369: Deserialization ignores other Object fields when Object or Array
1215
value used for enum
1316
(reported by Krishna G)

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

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

449-
// Sort by visibility (explicit over implicit); drop all but first of member
450-
// type (getter, setter etc) if there is visibility difference
451-
for (POJOPropertyBuilder property : props.values()) {
452-
property.trimByVisibility();
453-
}
454-
455449
// And use custom naming strategy, if applicable...
456-
// As per [databind#2979], should be AFTER trimming
450+
// 18-Jan-2021, tatu: To be done before trimming, to resolve
451+
// [databind#3368]
457452
PropertyNamingStrategy naming = _findNamingStrategy();
458453
if (naming != null) {
459454
_renameUsing(props, naming);
460455
}
461456

457+
// Sort by visibility (explicit over implicit); drop all but first of member
458+
// type (getter, setter etc) if there is visibility difference
459+
for (POJOPropertyBuilder property : props.values()) {
460+
property.trimByVisibility();
461+
}
462+
462463
// and, if required, apply wrapper name: note, MUST be done after
463464
// annotations are merged.
464465
if (_config.isEnabled(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME)) {

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

+43
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.lang.annotation.*;
44
import java.util.Arrays;
55
import java.util.List;
6+
import java.util.Map;
67

78
import com.fasterxml.jackson.annotation.*;
89

@@ -143,6 +144,34 @@ protected SnakeNameBean(@Name("id") String id,
143144
}
144145
}
145146

147+
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
148+
static class Value3368 {
149+
private String timeZone;
150+
private String utcZone;
151+
152+
@JsonProperty("time_zone")
153+
void unpackTimeZone(Map<String, String> timeZone) {
154+
this.setTimeZone(timeZone.get("name"));
155+
this.setUtcZone(timeZone.get("utc_zone"));
156+
}
157+
158+
public String getTimeZone() {
159+
return this.timeZone;
160+
}
161+
162+
public String getUtcZone() {
163+
return this.utcZone;
164+
}
165+
166+
public void setTimeZone(String timeZone) {
167+
this.timeZone = timeZone;
168+
}
169+
170+
public void setUtcZone(String utcZone) {
171+
this.utcZone = utcZone;
172+
}
173+
}
174+
146175
/*
147176
/**********************************************************
148177
/* Set up
@@ -346,6 +375,20 @@ public void testLowerCaseUnchangedNames() throws Exception
346375
assertEquals("_x", result._x);
347376
}
348377

378+
// [databind#3368]
379+
public void testSnakeCase3368() throws Exception
380+
{
381+
String test = " {\n" +
382+
" \"time_zone\": {\n" +
383+
" \"name\": \"XXX\",\n" +
384+
" \"utc_zone\": \"ZZZ\"\n" +
385+
" }\n" +
386+
" }";
387+
Value3368 res = sharedMapper().readerFor(Value3368.class).readValue(test);
388+
assertEquals("XXX", res.getTimeZone());
389+
assertEquals("ZZZ", res.getUtcZone());
390+
}
391+
349392
/*
350393
/**********************************************************
351394
/* Test methods for UPPER_SNAKE_CASE

0 commit comments

Comments
 (0)