Skip to content

Commit 6be6f47

Browse files
committed
Merge branch '2.19'
2 parents 58ca912 + 5ddf8b3 commit 6be6f47

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ public <T> T readPropertyValue(JsonParser p, BeanProperty prop, JavaType type)
11311131
public <T> T readTreeAsValue(JsonNode n, Class<T> targetType)
11321132
throws JacksonException
11331133
{
1134-
if (n == null) {
1134+
if (n == null || n.isMissingNode()) {
11351135
return null;
11361136
}
11371137
try (TreeTraversingParser p = _treeAsTokens(n)) {
@@ -1154,7 +1154,7 @@ public <T> T readTreeAsValue(JsonNode n, Class<T> targetType)
11541154
public <T> T readTreeAsValue(JsonNode n, JavaType targetType)
11551155
throws JacksonException
11561156
{
1157-
if (n == null) {
1157+
if (n == null || n.isMissingNode()) {
11581158
return null;
11591159
}
11601160
try (TreeTraversingParser p = _treeAsTokens(n)) {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package tools.jackson.databind;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import tools.jackson.core.JsonParser;
6+
import tools.jackson.databind.node.JsonNodeFactory;
7+
import tools.jackson.databind.testutil.DatabindTestUtil;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.assertNull;
11+
12+
public class DeserializationContextTest extends DatabindTestUtil
13+
{
14+
private final ObjectMapper MAPPER = newJsonMapper();
15+
16+
static class Bean4934 {
17+
public String value;
18+
}
19+
20+
// [databind#4934]
21+
@Test
22+
public void testTreeAsValueFromNulls() throws Exception
23+
{
24+
final JsonNodeFactory nodeF = MAPPER.getNodeFactory();
25+
try (JsonParser p = MAPPER.createParser("abc")) {
26+
DeserializationContext ctxt = MAPPER.readerFor(String.class)._deserializationContext(p);
27+
28+
assertNull(ctxt.readTreeAsValue(nodeF.nullNode(), Boolean.class));
29+
30+
// Fails on 3.0, investigate
31+
32+
//assertEquals(Boolean.FALSE, ctxt.readTreeAsValue(nodeF.nullNode(), Boolean.TYPE));
33+
34+
// Only fixed in 2.19:
35+
//assertNull(ctxt.readTreeAsValue(nodeF.nullNode(), Bean4934.class));
36+
37+
}
38+
}
39+
40+
// [databind#4934]
41+
@Test
42+
public void testTreeAsValueFromMissing() throws Exception
43+
{
44+
final JsonNodeFactory nodeF = MAPPER.getNodeFactory();
45+
try (JsonParser p = MAPPER.createParser("abc")) {
46+
DeserializationContext ctxt = MAPPER.readerFor(String.class)._deserializationContext(p);
47+
48+
assertNull(ctxt.readTreeAsValue(nodeF.missingNode(), Boolean.class));
49+
// Absent becomes `null` for now as well
50+
assertNull(ctxt.readTreeAsValue(nodeF.missingNode(), Boolean.TYPE));
51+
52+
// Only fixed in 2.19:
53+
//assertNull(ctxt.readTreeAsValue(nodeF.missingNode(), Bean4934.class));
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)