Skip to content

Commit

Permalink
Fix #1221
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 4, 2016
1 parent 504464d commit e1b2626
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Project: jackson-databind
#1211: Change `JsonValueSerializer` to get `AnnotatedMethod`, not "raw" method
#1217: `@JsonIgnoreProperties` on Pojo fields not working for deserialization
(reported by Lokesh K)
#1221: Use `Throwable.addSuppressed()` directly and/or via try-with-resources

2.7.4 (29-Apr-2016)

Expand Down
42 changes: 19 additions & 23 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3718,75 +3718,71 @@ private final void _writeCloseableValue(JsonGenerator g, Object value, Serializa
* for deserializing a single root value.
* Can be overridden if a custom context is needed.
*/
protected DefaultDeserializationContext createDeserializationContext(JsonParser jp,
protected DefaultDeserializationContext createDeserializationContext(JsonParser p,
DeserializationConfig cfg) {
return _deserializationContext.createInstance(cfg, jp, _injectableValues);
return _deserializationContext.createInstance(cfg, p, _injectableValues);
}

/**
* Actual implementation of value reading+binding operation.
*/
protected Object _readValue(DeserializationConfig cfg, JsonParser jp, JavaType valueType)
protected Object _readValue(DeserializationConfig cfg, JsonParser p, JavaType valueType)
throws IOException
{
/* First: may need to read the next token, to initialize
* state (either before first read from parser, or after
* previous token has been cleared)
*/
Object result;
JsonToken t = _initForReading(jp);
JsonToken t = _initForReading(p);
if (t == JsonToken.VALUE_NULL) {
// [JACKSON-643]: Ask JsonDeserializer what 'null value' to use:
DeserializationContext ctxt = createDeserializationContext(jp, cfg);
// Ask JsonDeserializer what 'null value' to use:
DeserializationContext ctxt = createDeserializationContext(p, cfg);
result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt);
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = null;
} else { // pointing to event other than null
DeserializationContext ctxt = createDeserializationContext(jp, cfg);
DeserializationContext ctxt = createDeserializationContext(p, cfg);
JsonDeserializer<Object> deser = _findRootDeserializer(ctxt, valueType);
// ok, let's get the value
if (cfg.useRootWrapping()) {
result = _unwrapAndDeserialize(jp, ctxt, cfg, valueType, deser);
result = _unwrapAndDeserialize(p, ctxt, cfg, valueType, deser);
} else {
result = deser.deserialize(jp, ctxt);
result = deser.deserialize(p, ctxt);
}
}
// Need to consume the token too
jp.clearCurrentToken();
p.clearCurrentToken();
return result;
}

protected Object _readMapAndClose(JsonParser jp, JavaType valueType)
protected Object _readMapAndClose(JsonParser p0, JavaType valueType)
throws IOException
{
try {
try (JsonParser p = p0) {
Object result;
JsonToken t = _initForReading(jp);
JsonToken t = _initForReading(p);
if (t == JsonToken.VALUE_NULL) {
// [JACKSON-643]: Ask JsonDeserializer what 'null value' to use:
DeserializationContext ctxt = createDeserializationContext(jp,
// Ask JsonDeserializer what 'null value' to use:
DeserializationContext ctxt = createDeserializationContext(p,
getDeserializationConfig());
result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt);
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = null;
} else {
DeserializationConfig cfg = getDeserializationConfig();
DeserializationContext ctxt = createDeserializationContext(jp, cfg);
DeserializationContext ctxt = createDeserializationContext(p, cfg);
JsonDeserializer<Object> deser = _findRootDeserializer(ctxt, valueType);
if (cfg.useRootWrapping()) {
result = _unwrapAndDeserialize(jp, ctxt, cfg, valueType, deser);
result = _unwrapAndDeserialize(p, ctxt, cfg, valueType, deser);
} else {
result = deser.deserialize(jp, ctxt);
result = deser.deserialize(p, ctxt);
}
ctxt.checkUnresolvedObjectId();
}
// Need to consume the token too
jp.clearCurrentToken();
p.clearCurrentToken();
return result;
} finally {
try {
jp.close();
} catch (IOException ioe) { }
}
}

Expand Down
16 changes: 4 additions & 12 deletions src/main/java/com/fasterxml/jackson/databind/ObjectReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1554,9 +1554,9 @@ protected JsonParser _considerFilter(final JsonParser p, boolean multiValue) {
? p : new FilteringParserDelegate(p, _filter, false, multiValue);
}

protected Object _bindAndClose(JsonParser p) throws IOException
protected Object _bindAndClose(JsonParser p0) throws IOException
{
try {
try (JsonParser p = p0) {
Object result;
JsonToken t = _initForReading(p);
if (t == JsonToken.VALUE_NULL) {
Expand All @@ -1583,20 +1583,12 @@ protected Object _bindAndClose(JsonParser p) throws IOException
}
}
return result;
} finally {
try {
p.close();
} catch (IOException ioe) { }
}
}

protected JsonNode _bindAndCloseAsTree(JsonParser p) throws IOException {
try {
protected JsonNode _bindAndCloseAsTree(JsonParser p0) throws IOException {
try (JsonParser p = p0) {
return _bindAsTree(p);
} finally {
try {
p.close();
} catch (IOException ioe) { }
}
}

Expand Down

0 comments on commit e1b2626

Please sign in to comment.