Skip to content

Commit 7fef1f3

Browse files
committed
Merge branch '2.19'
2 parents ecce8b9 + 33cf355 commit 7fef1f3

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Project: jackson-databind
7171
(reported by @dbachdev)
7272
#4922: Failing `@JsonMerge` with a custom Map
7373
(reported by @nlisker)
74+
#4932: Conversion of `MissingNode` throws `JsonProcessingException`
75+
(reported by @ludgerb)
7476
7577
2.18.2 (27-Nov-2024)
7678

src/main/java/tools/jackson/databind/ObjectMapper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,9 @@ protected Object _convert(Object fromValue, JavaType toValueType)
23822382
result = _findRootDeserializer(readCtxt, toValueType).getNullValue(readCtxt);
23832383
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
23842384
result = null;
2385+
} else if (t == JsonToken.NOT_AVAILABLE) {
2386+
// 28-Jan-2025, tatu: [databind#4932] Need to handle this case too
2387+
result = null;
23852388
} else { // pointing to event other than null
23862389
ValueDeserializer<Object> deser = _findRootDeserializer(readCtxt, toValueType);
23872390
// note: no handling of unwrapping
@@ -2539,6 +2542,9 @@ protected Object _readValue(DeserializationContextExt ctxt, JsonParser p,
25392542
result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt);
25402543
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
25412544
result = null;
2545+
} else if (t == JsonToken.NOT_AVAILABLE) {
2546+
// 28-Jan-2025, tatu: [databind#4932] Need to handle this case too
2547+
result = null;
25422548
} else { // pointing to event other than null
25432549
result = ctxt.readRootValue(p, valueType, _findRootDeserializer(ctxt, valueType), null);
25442550
}
@@ -2563,6 +2569,9 @@ protected Object _readMapAndClose(DeserializationContextExt ctxt,
25632569
result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt);
25642570
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
25652571
result = null;
2572+
} else if (t == JsonToken.NOT_AVAILABLE) {
2573+
// 28-Jan-2025, tatu: [databind#4932] Need to handle this case too
2574+
result = null;
25662575
} else {
25672576
result = ctxt.readRootValue(p, valueType,
25682577
_findRootDeserializer(ctxt, valueType), null);

src/main/java/tools/jackson/databind/ObjectReader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,9 @@ protected Object _bind(DeserializationContextExt ctxt,
16181618
}
16191619
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
16201620
result = valueToUpdate;
1621+
} else if (t == JsonToken.NOT_AVAILABLE) {
1622+
// 28-Jan-2025, tatu: [databind#4932] Need to handle this case too
1623+
result = valueToUpdate;
16211624
} else { // pointing to event other than null
16221625
result = ctxt.readRootValue(p, _valueType, _findRootDeserializer(ctxt), _valueToUpdate);
16231626
}
@@ -1643,6 +1646,9 @@ protected Object _bindAndClose(DeserializationContextExt ctxt,
16431646
}
16441647
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
16451648
result = _valueToUpdate;
1649+
} else if (t == JsonToken.NOT_AVAILABLE) {
1650+
// 28-Jan-2025, tatu: [databind#4932] Need to handle this case too
1651+
result = _valueToUpdate;
16461652
} else {
16471653
result = ctxt.readRootValue(p, _valueType, _findRootDeserializer(ctxt), _valueToUpdate);
16481654
}

src/test/java/tools/jackson/databind/node/JsonNodeConversionsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,4 +437,15 @@ public void testValueToTree() throws Exception
437437
assertEquals(wrapRootMapper.readValue(expected, Map.class), wrapRootMapper.readValue(wrapRootMapper.writeValueAsString(value), Map.class));
438438
assertEquals(wrapRootMapper.readValue(expected, Map.class), wrapRootMapper.readValue(wrapRootMapper.valueToTree(value).toString(), Map.class));
439439
}
440+
441+
// [databind#4932]: handling of `MissingNode` wrt conversions
442+
@Test
443+
public void treeToValueWithMissingNode4932() throws Exception {
444+
assertNull(MAPPER.treeToValue(MAPPER.nullNode(), Object.class));
445+
assertNull(MAPPER.treeToValue(MAPPER.missingNode(), Object.class));
446+
447+
ObjectReader r = MAPPER.readerFor(Object.class);
448+
assertNull(r.treeToValue(MAPPER.nullNode(), Object.class));
449+
assertNull(r.treeToValue(MAPPER.missingNode(), Object.class));
450+
}
440451
}

0 commit comments

Comments
 (0)