Skip to content

Commit 2618227

Browse files
authored
Fix #4932 (#4937)
1 parent 7ced550 commit 2618227

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Project: jackson-databind
3131
(reported by @dbachdev)
3232
#4922: Failing `@JsonMerge` with a custom Map
3333
(reported by @nlisker)
34+
#4932: Conversion of `MissingNode` throws `JsonProcessingException`
35+
(reported by @ludgerb)
3436

3537
2.18.2 (27-Nov-2024)
3638

src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4897,6 +4897,9 @@ protected Object _readValue(DeserializationConfig cfg, JsonParser p,
48974897
result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt);
48984898
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
48994899
result = null;
4900+
} else if (t == JsonToken.NOT_AVAILABLE) {
4901+
// 28-Jan-2025, tatu: [databind#4932] Need to handle this case too
4902+
result = null;
49004903
} else { // pointing to event other than null
49014904
result = ctxt.readRootValue(p, valueType, _findRootDeserializer(ctxt, valueType), null);
49024905
}
@@ -4921,6 +4924,9 @@ protected Object _readMapAndClose(JsonParser p0, JavaType valueType)
49214924
result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt);
49224925
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
49234926
result = null;
4927+
} else if (t == JsonToken.NOT_AVAILABLE) {
4928+
// 28-Jan-2025, tatu: [databind#4932] Need to handle this case too
4929+
result = null;
49244930
} else {
49254931
result = ctxt.readRootValue(p, valueType,
49264932
_findRootDeserializer(ctxt, valueType), null);

src/main/java/com/fasterxml/jackson/databind/ObjectReader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,9 @@ protected Object _bind(JsonParser p, Object valueToUpdate) throws IOException
20952095
}
20962096
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
20972097
result = valueToUpdate;
2098+
} else if (t == JsonToken.NOT_AVAILABLE) {
2099+
// 28-Jan-2025, tatu: [databind#4932] Need to handle this case too
2100+
result = valueToUpdate;
20982101
} else { // pointing to event other than null
20992102
result = ctxt.readRootValue(p, _valueType, _findRootDeserializer(ctxt), _valueToUpdate);
21002103
}
@@ -2121,6 +2124,9 @@ protected Object _bindAndClose(JsonParser p0) throws IOException
21212124
}
21222125
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
21232126
result = _valueToUpdate;
2127+
} else if (t == JsonToken.NOT_AVAILABLE) {
2128+
// 28-Jan-2025, tatu: [databind#4932] Need to handle this case too
2129+
result = _valueToUpdate;
21242130
} else {
21252131
result = ctxt.readRootValue(p, _valueType, _findRootDeserializer(ctxt), _valueToUpdate);
21262132
}

src/test/java/com/fasterxml/jackson/databind/node/JsonNodeConversionsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,15 @@ public void testValueToTree() throws Exception
419419
assertEquals(wrapRootMapper.readValue(expected, Map.class), wrapRootMapper.readValue(wrapRootMapper.writeValueAsString(value), Map.class));
420420
assertEquals(wrapRootMapper.readValue(expected, Map.class), wrapRootMapper.readValue(wrapRootMapper.valueToTree(value).toString(), Map.class));
421421
}
422+
423+
// [databind#4932]: handling of `MissingNode` wrt conversions
424+
@Test
425+
public void treeToValueWithMissingNode4932() throws Exception {
426+
assertNull(MAPPER.treeToValue(MAPPER.nullNode(), Object.class));
427+
assertNull(MAPPER.treeToValue(MAPPER.missingNode(), Object.class));
428+
429+
ObjectReader r = MAPPER.readerFor(Object.class);
430+
assertNull(r.treeToValue(MAPPER.nullNode(), Object.class));
431+
assertNull(r.treeToValue(MAPPER.missingNode(), Object.class));
432+
}
422433
}

0 commit comments

Comments
 (0)