diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index e682236612..c1b946a8d6 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -9,6 +9,8 @@ Project: jackson-databind #2962: Auto-detection of constructor-based creator method skipped if there is an annotated factory-based creator method (regression from 2.11) (reported by Halil I-S) +#2972: `ObjectMapper.treeToValue()` no longer invokes `JsonDeserializer.getNullValue()` + (reported by andpal@github) #2973: DeserializationProblemHandler is not invoked when trying to deserializing String (reported by zigzago@github) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index a4e472801a..328e618508 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -2796,7 +2796,7 @@ public T readValue(JsonParser p, Class valueType) { _assertNotNull("p", p); return (T) _readValue(getDeserializationConfig(), p, _typeFactory.constructType(valueType)); - } + } /** * Method to deserialize JSON content into a Java type, reference @@ -3242,10 +3242,6 @@ public T treeToValue(TreeNode n, Class valueType) return (T) n; } final JsonToken tt = n.asToken(); - // 22-Aug-2019, tatu: [databind#2430] Consider "null node" (minor optimization) - if (tt == JsonToken.VALUE_NULL) { - return null; - } // 20-Apr-2016, tatu: Another thing: for VALUE_EMBEDDED_OBJECT, assume similar // short-cut coercion if (tt == JsonToken.VALUE_EMBEDDED_OBJECT) { @@ -3256,6 +3252,12 @@ public T treeToValue(TreeNode n, Class valueType) } } } + // 22-Aug-2019, tatu: [databind#2430] Consider "null node" (minor optimization) + // 08-Dec-2020, tatu: Alas, lead to [databind#2972], optimization gets complicated + // so leave out for now... + /*if (tt == JsonToken.VALUE_NULL) { + return null; + }*/ return readValue(treeAsTokens(n), valueType); } catch (JsonProcessingException e) { // 12-Nov-2020, tatu: These can legit happen, during conversion, especially diff --git a/src/test/java/com/fasterxml/jackson/databind/node/TestConversions.java b/src/test/java/com/fasterxml/jackson/databind/node/TestConversions.java index f94f052b1f..99b75dca1c 100644 --- a/src/test/java/com/fasterxml/jackson/databind/node/TestConversions.java +++ b/src/test/java/com/fasterxml/jackson/databind/node/TestConversions.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import static org.junit.Assert.*; @@ -326,5 +327,11 @@ public void testConversionsOfNull() throws Exception // and vice versa Object pojo = MAPPER.treeToValue(n, Root.class); assertNull(pojo); + + // [databind#2972] + AtomicReference result = MAPPER.treeToValue(NullNode.instance, + AtomicReference.class); + assertNotNull(result); + assertNull(result.get()); } }