Skip to content

Commit

Permalink
Fix #2972
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 9, 2020
1 parent 7fd0af3 commit 9dab814
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2796,7 +2796,7 @@ public <T> T readValue(JsonParser p, Class<T> valueType)
{
_assertNotNull("p", p);
return (T) _readValue(getDeserializationConfig(), p, _typeFactory.constructType(valueType));
}
}

/**
* Method to deserialize JSON content into a Java type, reference
Expand Down Expand Up @@ -3242,10 +3242,6 @@ public <T> T treeToValue(TreeNode n, Class<T> 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) {
Expand All @@ -3256,6 +3252,12 @@ public <T> T treeToValue(TreeNode n, Class<T> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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());
}
}

0 comments on commit 9dab814

Please sign in to comment.