Skip to content

Commit 9dab814

Browse files
committed
Fix #2972
1 parent 7fd0af3 commit 9dab814

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project: jackson-databind
99
#2962: Auto-detection of constructor-based creator method skipped if there is
1010
an annotated factory-based creator method (regression from 2.11)
1111
(reported by Halil I-S)
12+
#2972: `ObjectMapper.treeToValue()` no longer invokes `JsonDeserializer.getNullValue()`
13+
(reported by andpal@github)
1214
#2973: DeserializationProblemHandler is not invoked when trying to deserializing String
1315
(reported by zigzago@github)
1416

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,7 +2796,7 @@ public <T> T readValue(JsonParser p, Class<T> valueType)
27962796
{
27972797
_assertNotNull("p", p);
27982798
return (T) _readValue(getDeserializationConfig(), p, _typeFactory.constructType(valueType));
2799-
}
2799+
}
28002800

28012801
/**
28022802
* Method to deserialize JSON content into a Java type, reference
@@ -3242,10 +3242,6 @@ public <T> T treeToValue(TreeNode n, Class<T> valueType)
32423242
return (T) n;
32433243
}
32443244
final JsonToken tt = n.asToken();
3245-
// 22-Aug-2019, tatu: [databind#2430] Consider "null node" (minor optimization)
3246-
if (tt == JsonToken.VALUE_NULL) {
3247-
return null;
3248-
}
32493245
// 20-Apr-2016, tatu: Another thing: for VALUE_EMBEDDED_OBJECT, assume similar
32503246
// short-cut coercion
32513247
if (tt == JsonToken.VALUE_EMBEDDED_OBJECT) {
@@ -3256,6 +3252,12 @@ public <T> T treeToValue(TreeNode n, Class<T> valueType)
32563252
}
32573253
}
32583254
}
3255+
// 22-Aug-2019, tatu: [databind#2430] Consider "null node" (minor optimization)
3256+
// 08-Dec-2020, tatu: Alas, lead to [databind#2972], optimization gets complicated
3257+
// so leave out for now...
3258+
/*if (tt == JsonToken.VALUE_NULL) {
3259+
return null;
3260+
}*/
32593261
return readValue(treeAsTokens(n), valueType);
32603262
} catch (JsonProcessingException e) {
32613263
// 12-Nov-2020, tatu: These can legit happen, during conversion, especially

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.math.BigDecimal;
55
import java.util.*;
6+
import java.util.concurrent.atomic.AtomicReference;
67

78
import static org.junit.Assert.*;
89

@@ -326,5 +327,11 @@ public void testConversionsOfNull() throws Exception
326327
// and vice versa
327328
Object pojo = MAPPER.treeToValue(n, Root.class);
328329
assertNull(pojo);
330+
331+
// [databind#2972]
332+
AtomicReference<?> result = MAPPER.treeToValue(NullNode.instance,
333+
AtomicReference.class);
334+
assertNotNull(result);
335+
assertNull(result.get());
329336
}
330337
}

0 commit comments

Comments
 (0)