Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 23, 2019
1 parent 21220ee commit 6532c75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
13 changes: 3 additions & 10 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2393,9 +2393,7 @@ public <T> T readValue(JsonParser p, JavaType valueType)
public <T extends TreeNode> T readTree(JsonParser p)
throws IOException, JsonProcessingException
{
/* 05-Aug-2011, tatu: Also, must check for EOF here before
* calling readValue(), since that'll choke on it otherwise
*/
// Must check for EOF here before calling readValue(), since that'll choke on it otherwise
DeserializationConfig cfg = getDeserializationConfig();
JsonToken t = p.getCurrentToken();
if (t == null) {
Expand All @@ -2404,17 +2402,13 @@ public <T extends TreeNode> T readTree(JsonParser p)
return null;
}
}
// NOTE! _readValue() will check for trailing tokens
JsonNode n = (JsonNode) _readValue(cfg, p, JSON_NODE_TYPE);
if (n == null) {
n = getNodeFactory().nullNode();
}
@SuppressWarnings("unchecked")
T result = (T) n;
/*
if (cfg.isEnabled(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)) {
_verifyNoTrailingTokens(p, ctxt, valueType);
}
*/
return result;
}

Expand Down Expand Up @@ -4029,14 +4023,13 @@ protected JsonNode _readTreeAndClose(JsonParser p0) throws IOException
} else {
ctxt = createDeserializationContext(p, cfg);
JsonDeserializer<Object> deser = _findRootDeserializer(ctxt, valueType);
Object result;
if (cfg.useRootWrapping()) {
resultNode = (JsonNode) _unwrapAndDeserialize(p, ctxt, cfg, valueType, deser);
} else {
resultNode = (JsonNode) deser.deserialize(p, ctxt);
}
}
if (cfg.isEnabled(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)) {
if (checkTrailing) {
_verifyNoTrailingTokens(p, ctxt, valueType);
}
// No ObjectIds so can ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public void testNullFromEOFWithParserAndReader() throws Exception
_assertNullTree(MAPPER.reader().readTree(p));
}
}
*/

*/
// [databind#2211]: when passing content sources OTHER than `JsonParser`,
// return "missing node" instead of alternate (return `null`, throw exception).
public void testMissingNodeForEOFOtherMapper() throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
public class TreeReadViaMapperTest extends BaseMapTest
{
private final ObjectMapper MAPPER = objectMapper();

public void testSimple() throws Exception
{
final String JSON = SAMPLE_DOC_JSON_SPEC;
Expand All @@ -22,9 +24,9 @@ public void testSimple() throws Exception
JsonNode result;

if (type == 0) {
result = objectMapper().readTree(new StringReader(JSON));
result = MAPPER.readTree(new StringReader(JSON));
} else {
result = objectMapper().readTree(JSON);
result = MAPPER.readTree(JSON);
}

assertType(result, ObjectNode.class);
Expand Down Expand Up @@ -90,9 +92,8 @@ public void testSimple() throws Exception

public void testMixed() throws IOException
{
ObjectMapper om = new ObjectMapper();
String JSON = "{\"node\" : { \"a\" : 3 }, \"x\" : 9 }";
Bean bean = om.readValue(JSON, Bean.class);
Bean bean = MAPPER.readValue(JSON, Bean.class);

assertEquals(9, bean._x);
JsonNode n = bean._node;
Expand All @@ -115,15 +116,26 @@ public void testEOF() throws Exception
;
JsonFactory jf = new JsonFactory();
JsonParser p = jf.createParser(new StringReader(JSON));
JsonNode result = objectMapper().readTree(p);
JsonNode result = MAPPER.readTree(p);

assertTrue(result.isObject());
assertEquals(4, result.size());

assertNull(objectMapper().readTree(p));
assertNull(MAPPER.readTree(p));
p.close();
}

public void testNullViaParser() throws Exception
{
final String JSON = " null ";
JsonFactory jf = new JsonFactory();

try (JsonParser p = jf.createParser(new StringReader(JSON))) {
final JsonNode result = MAPPER.readTree(p);
assertTrue(result.isNull());
}
}

public void testMultiple() throws Exception
{
String JSON = "12 \"string\" [ 1, 2, 3 ]";
Expand Down

0 comments on commit 6532c75

Please sign in to comment.