Skip to content

Commit

Permalink
Fix #1675
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 4, 2019
1 parent 6814284 commit 38a61e0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Project: jackson-databind

2.10.0 (not yet released)

#1675: Remove "impossible" `IOException` in `readTree()` and `readValue()` `ObjectMapper`
methods which accept Strings
(requested by matthew-pwnieexpress@github)
#2059: Remove `final` modifier for `TypeFactory`
(requested by Thibaut R)
#2115: Support naive deserialization of `Serializable` values as "untyped", same
Expand Down
48 changes: 23 additions & 25 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2531,8 +2531,14 @@ public JsonNode readTree(Reader r) throws IOException {
* Same as {@link #readTree(InputStream)} except content read from
* passed-in {@link String}
*/
public JsonNode readTree(String content) throws IOException {
return _readTreeAndClose(_jsonFactory.createParser(content));
public JsonNode readTree(String content) throws JsonProcessingException, JsonMappingException {
try { // since 2.10 remove "impossible" IOException as per [databind#1675]
return _readTreeAndClose(_jsonFactory.createParser(content));
} catch (JsonProcessingException e) {
throw e;
} catch (IOException e) { // shouldn't really happen but being declared need to
throw JsonMappingException.fromUnexpectedIOE(e);
}
}

/**
Expand Down Expand Up @@ -2936,59 +2942,51 @@ public <T> T readValue(URL src, JavaType valueType)

/**
* Method to deserialize JSON content from given JSON content String.
*
* @throws IOException if a low-level I/O problem (unexpected end-of-input,
* network error) occurs (passed through as-is without additional wrapping -- note
* that this is one case where {@link DeserializationFeature#WRAP_EXCEPTIONS}
* does NOT result in wrapping of exception even if enabled)
*
* @throws JsonParseException if underlying input contains invalid content
* of type {@link JsonParser} supports (JSON for default case)
* @throws JsonMappingException if the input JSON structure does not match structure
* expected for result type (or has other mismatch issues)
*/
@SuppressWarnings("unchecked")
public <T> T readValue(String content, Class<T> valueType)
throws IOException, JsonParseException, JsonMappingException
throws JsonProcessingException, JsonMappingException
{
return (T) _readMapAndClose(_jsonFactory.createParser(content), _typeFactory.constructType(valueType));
return readValue(content, _typeFactory.constructType(valueType));
}

/**
* Method to deserialize JSON content from given JSON content String.
*
* @throws IOException if a low-level I/O problem (unexpected end-of-input,
* network error) occurs (passed through as-is without additional wrapping -- note
* that this is one case where {@link DeserializationFeature#WRAP_EXCEPTIONS}
* does NOT result in wrapping of exception even if enabled)
*
* @throws JsonParseException if underlying input contains invalid content
* of type {@link JsonParser} supports (JSON for default case)
* @throws JsonMappingException if the input JSON structure does not match structure
* expected for result type (or has other mismatch issues)
*/
@SuppressWarnings({ "unchecked" })
public <T> T readValue(String content, TypeReference<T> valueTypeRef)
throws IOException, JsonParseException, JsonMappingException
throws JsonProcessingException, JsonMappingException
{
return (T) _readMapAndClose(_jsonFactory.createParser(content), _typeFactory.constructType(valueTypeRef));
return readValue(content, _typeFactory.constructType(valueTypeRef));
}

/**
* Method to deserialize JSON content from given JSON content String.
*
* @throws IOException if a low-level I/O problem (unexpected end-of-input,
* network error) occurs (passed through as-is without additional wrapping -- note
* that this is one case where {@link DeserializationFeature#WRAP_EXCEPTIONS}
* does NOT result in wrapping of exception even if enabled)
*
* @throws JsonParseException if underlying input contains invalid content
* of type {@link JsonParser} supports (JSON for default case)
* @throws JsonMappingException if the input JSON structure does not match structure
* expected for result type (or has other mismatch issues)
*/
@SuppressWarnings("unchecked")
public <T> T readValue(String content, JavaType valueType)
throws IOException, JsonParseException, JsonMappingException
throws JsonProcessingException, JsonMappingException
{
return (T) _readMapAndClose(_jsonFactory.createParser(content), valueType);
try { // since 2.10 remove "impossible" IOException as per [databind#1675]
return (T) _readMapAndClose(_jsonFactory.createParser(content), valueType);
} catch (JsonProcessingException e) {
throw e;
} catch (IOException e) { // shouldn't really happen but being declared need to
throw JsonMappingException.fromUnexpectedIOE(e);
}
}

@SuppressWarnings("unchecked")
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/com/fasterxml/jackson/databind/ObjectReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1217,13 +1217,18 @@ public <T> T readValue(Reader src) throws IOException
* was specified with {@link #withValueToUpdate(Object)}.
*/
@SuppressWarnings("unchecked")
public <T> T readValue(String src) throws IOException
public <T> T readValue(String src) throws JsonProcessingException, JsonMappingException
{
if (_dataFormatReaders != null) {
_reportUndetectableSource(src);
}

return (T) _bindAndClose(_considerFilter(_parserFactory.createParser(src), false));
try { // since 2.10 remove "impossible" IOException as per [databind#1675]
return (T) _bindAndClose(_considerFilter(_parserFactory.createParser(src), false));
} catch (JsonProcessingException e) {
throw e;
} catch (IOException e) { // shouldn't really happen but being declared need to
throw JsonMappingException.fromUnexpectedIOE(e);
}
}

/**
Expand Down Expand Up @@ -1361,12 +1366,18 @@ public JsonNode readTree(Reader r) throws IOException
* Same as {@link #readTree(InputStream)} except content read from
* passed-in {@link String}
*/
public JsonNode readTree(String json) throws IOException
public JsonNode readTree(String json) throws JsonProcessingException, JsonMappingException
{
if (_dataFormatReaders != null) {
_reportUndetectableSource(json);
}
return _bindAndCloseAsTree(_considerFilter(_parserFactory.createParser(json), false));
try { // since 2.10 remove "impossible" IOException as per [databind#1675]
return _bindAndCloseAsTree(_considerFilter(_parserFactory.createParser(json), false));
} catch (JsonProcessingException e) {
throw e;
} catch (IOException e) { // shouldn't really happen but being declared need to
throw JsonMappingException.fromUnexpectedIOE(e);
}
}

/**
Expand Down Expand Up @@ -1943,7 +1954,7 @@ protected InputStream _inputStream(File f) throws IOException {
return new FileInputStream(f);
}

protected void _reportUndetectableSource(Object src) throws JsonProcessingException
protected void _reportUndetectableSource(Object src) throws JsonParseException
{
// 17-Aug-2015, tatu: Unfortunately, no parser/generator available so:
throw new JsonParseException(null, "Cannot use source of type "
Expand Down

0 comments on commit 38a61e0

Please sign in to comment.