|
| 1 | +package com.fasterxml.jackson.databind; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.core.JsonParser; |
| 4 | +import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 5 | +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; |
| 6 | + |
| 7 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 9 | + |
| 10 | +import org.junit.jupiter.api.Test; |
| 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).createDeserializationContext(p); |
| 27 | + |
| 28 | + assertNull(ctxt.readTreeAsValue(nodeF.nullNode(), Boolean.class)); |
| 29 | + assertEquals(Boolean.FALSE, ctxt.readTreeAsValue(nodeF.nullNode(), Boolean.TYPE)); |
| 30 | + |
| 31 | + // Only fixed in 2.19: |
| 32 | + //assertNull(ctxt.readTreeAsValue(nodeF.nullNode(), Bean4934.class)); |
| 33 | + |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + // [databind#4934] |
| 38 | + @Test |
| 39 | + public void testTreeAsValueFromMissing() throws Exception |
| 40 | + { |
| 41 | + final JsonNodeFactory nodeF = MAPPER.getNodeFactory(); |
| 42 | + try (JsonParser p = MAPPER.createParser("abc")) { |
| 43 | + DeserializationContext ctxt = MAPPER.readerFor(String.class).createDeserializationContext(p); |
| 44 | + |
| 45 | + assertNull(ctxt.readTreeAsValue(nodeF.missingNode(), Boolean.class)); |
| 46 | + // Absent becomes `null` for now as well |
| 47 | + assertNull(ctxt.readTreeAsValue(nodeF.missingNode(), Boolean.TYPE)); |
| 48 | + |
| 49 | + // Only fixed in 2.19: |
| 50 | + //assertNull(ctxt.readTreeAsValue(nodeF.missingNode(), Bean4934.class)); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments