Skip to content

ObjectMapper.readTree() methods do not return null on end-of-input #1406

@fabriziocucci

Description

@fabriziocucci

Hi,

the Javadoc for the readTree(InputStream) method goes like this:

If a low-level I/O problem (missing input, network error) occurs, a IOException will be thrown. If a parsing problem occurs (invalid JSON), JsonParseException will be thrown. If no content is found from input (end-of-input), Java null will be returned.

But if I try to use it with an empty file (through the FileInputStream) I get the following exception:

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input

I was wondering whether it is the code not to be aligned with the expected behavior or it is just the Javadoc.

Ideally, from a consumer prospective, it would have been nice to return a sort of "identity" JsonNode (e.g. an empty JsonNodeType.OBJECT or a JsonNodeType.MISSING) in case of empty file, stream, etc. But I can imagine that such a change (if it even makes sense) could cause some backward compatibility issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions