@@ -1166,14 +1166,14 @@ public JsonParser treeAsTokens(TreeNode n) {
1166
1166
@ SuppressWarnings ("unchecked" )
1167
1167
@ Override
1168
1168
public <T extends TreeNode > T readTree (JsonParser p ) throws IOException {
1169
- return (T ) _bindAsTree (p );
1169
+ return (T ) _bindAsTreeOrNull (p );
1170
1170
}
1171
-
1171
+
1172
1172
@ Override
1173
1173
public void writeTree (JsonGenerator g , TreeNode rootNode ) {
1174
1174
throw new UnsupportedOperationException ();
1175
1175
}
1176
-
1176
+
1177
1177
/*
1178
1178
/**********************************************************
1179
1179
/* Deserialization methods; others similar to what ObjectMapper has
@@ -1669,9 +1669,7 @@ protected final JsonNode _bindAndCloseAsTree(JsonParser p0) throws IOException {
1669
1669
1670
1670
protected final JsonNode _bindAsTree (JsonParser p ) throws IOException
1671
1671
{
1672
- // 27-Oct-2016, tatu: Need to inline `_initForReading()` due to
1673
- // special requirements by tree reading (no fail on eof)
1674
-
1672
+ // Need to inline `_initForReading()` due to tree reading handling end-of-input specially
1675
1673
_config .initialize (p );
1676
1674
if (_schema != null ) {
1677
1675
p .setSchema (_schema );
@@ -1680,29 +1678,63 @@ protected final JsonNode _bindAsTree(JsonParser p) throws IOException
1680
1678
JsonToken t = p .getCurrentToken ();
1681
1679
if (t == null ) {
1682
1680
t = p .nextToken ();
1683
- if (t == null ) { // [databind#1406]: expose end-of-input as `null`
1684
- // [databind#2211]: return `MissingNode` (supercedes [databind#1406] which dictated
1685
- // returning `null`
1681
+ if (t == null ) {
1686
1682
return _config .getNodeFactory ().missingNode ();
1687
1683
}
1688
1684
}
1689
- DeserializationContext ctxt = createDeserializationContext ( p ) ;
1685
+ final JsonNode resultNode ;
1690
1686
if (t == JsonToken .VALUE_NULL ) {
1691
- return _config .getNodeFactory ().nullNode ();
1692
- }
1693
- JsonDeserializer <Object > deser = _findTreeDeserializer (ctxt );
1694
- Object result ;
1695
- if (_unwrapRoot ) {
1696
- result = _unwrapAndDeserialize (p , ctxt , JSON_NODE_TYPE , deser );
1687
+ resultNode = _config .getNodeFactory ().nullNode ();
1697
1688
} else {
1698
- result = deser .deserialize (p , ctxt );
1699
- if (_config .isEnabled (DeserializationFeature .FAIL_ON_TRAILING_TOKENS )) {
1700
- _verifyNoTrailingTokens (p , ctxt , JSON_NODE_TYPE );
1689
+ final DeserializationContext ctxt = createDeserializationContext (p );
1690
+ final JsonDeserializer <Object > deser = _findTreeDeserializer (ctxt );
1691
+ if (_unwrapRoot ) {
1692
+ resultNode = (JsonNode ) _unwrapAndDeserialize (p , ctxt , JSON_NODE_TYPE , deser );
1693
+ } else {
1694
+ resultNode = (JsonNode ) deser .deserialize (p , ctxt );
1695
+ if (_config .isEnabled (DeserializationFeature .FAIL_ON_TRAILING_TOKENS )) {
1696
+ _verifyNoTrailingTokens (p , ctxt , JSON_NODE_TYPE );
1697
+ }
1701
1698
}
1702
1699
}
1703
- return ( JsonNode ) result ;
1700
+ return resultNode ;
1704
1701
}
1705
1702
1703
+ /**
1704
+ * Same as {@link #_bindAsTree} except end-of-input is reported by returning
1705
+ * {@code null}, not "missing node"
1706
+ */
1707
+ protected final JsonNode _bindAsTreeOrNull (JsonParser p ) throws IOException
1708
+ {
1709
+ _config .initialize (p );
1710
+ if (_schema != null ) {
1711
+ p .setSchema (_schema );
1712
+ }
1713
+ JsonToken t = p .getCurrentToken ();
1714
+ if (t == null ) {
1715
+ t = p .nextToken ();
1716
+ if (t == null ) {
1717
+ return null ;
1718
+ }
1719
+ }
1720
+ final JsonNode resultNode ;
1721
+ if (t == JsonToken .VALUE_NULL ) {
1722
+ resultNode = _config .getNodeFactory ().nullNode ();
1723
+ } else {
1724
+ final DeserializationContext ctxt = createDeserializationContext (p );
1725
+ final JsonDeserializer <Object > deser = _findTreeDeserializer (ctxt );
1726
+ if (_unwrapRoot ) {
1727
+ resultNode = (JsonNode ) _unwrapAndDeserialize (p , ctxt , JSON_NODE_TYPE , deser );
1728
+ } else {
1729
+ resultNode = (JsonNode ) deser .deserialize (p , ctxt );
1730
+ if (_config .isEnabled (DeserializationFeature .FAIL_ON_TRAILING_TOKENS )) {
1731
+ _verifyNoTrailingTokens (p , ctxt , JSON_NODE_TYPE );
1732
+ }
1733
+ }
1734
+ }
1735
+ return resultNode ;
1736
+ }
1737
+
1706
1738
/**
1707
1739
* @since 2.1
1708
1740
*/
0 commit comments