Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 30, 2025
2 parents 58ca912 + 5ddf8b3 commit 6be6f47
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ public <T> T readPropertyValue(JsonParser p, BeanProperty prop, JavaType type)
public <T> T readTreeAsValue(JsonNode n, Class<T> targetType)
throws JacksonException
{
if (n == null) {
if (n == null || n.isMissingNode()) {
return null;
}
try (TreeTraversingParser p = _treeAsTokens(n)) {
Expand All @@ -1154,7 +1154,7 @@ public <T> T readTreeAsValue(JsonNode n, Class<T> targetType)
public <T> T readTreeAsValue(JsonNode n, JavaType targetType)
throws JacksonException
{
if (n == null) {
if (n == null || n.isMissingNode()) {
return null;
}
try (TreeTraversingParser p = _treeAsTokens(n)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package tools.jackson.databind;

import org.junit.jupiter.api.Test;

import tools.jackson.core.JsonParser;
import tools.jackson.databind.node.JsonNodeFactory;
import tools.jackson.databind.testutil.DatabindTestUtil;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class DeserializationContextTest extends DatabindTestUtil
{
private final ObjectMapper MAPPER = newJsonMapper();

static class Bean4934 {
public String value;
}

// [databind#4934]
@Test
public void testTreeAsValueFromNulls() throws Exception
{
final JsonNodeFactory nodeF = MAPPER.getNodeFactory();
try (JsonParser p = MAPPER.createParser("abc")) {
DeserializationContext ctxt = MAPPER.readerFor(String.class)._deserializationContext(p);

assertNull(ctxt.readTreeAsValue(nodeF.nullNode(), Boolean.class));

// Fails on 3.0, investigate

//assertEquals(Boolean.FALSE, ctxt.readTreeAsValue(nodeF.nullNode(), Boolean.TYPE));

// Only fixed in 2.19:
//assertNull(ctxt.readTreeAsValue(nodeF.nullNode(), Bean4934.class));

}
}

// [databind#4934]
@Test
public void testTreeAsValueFromMissing() throws Exception
{
final JsonNodeFactory nodeF = MAPPER.getNodeFactory();
try (JsonParser p = MAPPER.createParser("abc")) {
DeserializationContext ctxt = MAPPER.readerFor(String.class)._deserializationContext(p);

assertNull(ctxt.readTreeAsValue(nodeF.missingNode(), Boolean.class));
// Absent becomes `null` for now as well
assertNull(ctxt.readTreeAsValue(nodeF.missingNode(), Boolean.TYPE));

// Only fixed in 2.19:
//assertNull(ctxt.readTreeAsValue(nodeF.missingNode(), Bean4934.class));
}
}
}

0 comments on commit 6be6f47

Please sign in to comment.