Skip to content

Commit 8ed56f0

Browse files
dlwldnjs1009cowtowncoder
authored andcommitted
Fix Map.Entry deserialization for property-level NATURAL override (#5867)
Follow-up to #1419 / #5397. POJOWrappedDeserializer.createContextual() still used a POJO-wrapped deserializer when property-level @jsonformat(shape = NATURAL) should reverse a global POJO format override. Use constructDefault() instead so deserialization honors the more specific property override, and add a regression test for that case.
1 parent 60d2afa commit 8ed56f0

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/main/java/tools/jackson/databind/deser/jdk/MapEntryDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public ValueDeserializer<?> createContextual(DeserializationContext ctxt,
405405
{
406406
// May override back to standard too:
407407
if (Boolean.FALSE.equals(_shouldDeserializeAsPOJO(ctxt, property))) {
408-
return constructAsPOJO(ctxt, _valueType)
408+
return constructDefault(ctxt, _valueType)
409409
._createContextual2(ctxt, property);
410410
}
411411
return _createContextual2(ctxt, property);

src/test/java/tools/jackson/databind/format/MapEntryFormatTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@ public void testDefaultShapeOverride() throws Exception
231231
|| mapper.writeValueAsString(input).equals(a2q("{'value':'bar','key':'foo'}")));
232232
}
233233

234+
// [databind#1419]: Property-level NATURAL should reverse global POJO override on deserialization
235+
@Test
236+
public void testDefaultPOJOOverrideWithPropertyNatural() throws Exception
237+
{
238+
ObjectMapper mapper = jsonMapperBuilder()
239+
.withConfigOverride(Map.Entry.class,
240+
o -> o.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.POJO)))
241+
.build();
242+
// BeanWithMapEntry.entry has @JsonFormat(shape=NATURAL),
243+
// so despite global POJO default, this property should use natural format
244+
String json = a2q("{'entry':{'foo':'bar'}}");
245+
BeanWithMapEntry result = mapper.readValue(json, BeanWithMapEntry.class);
246+
assertEquals("foo", result.entry.getKey());
247+
assertEquals("bar", result.entry.getValue());
248+
}
249+
234250
/*
235251
/**********************************************************
236252
/* Test methods, as-POJO (Shape) [databind#1419]

0 commit comments

Comments
 (0)