Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JacksonJsonProvider MessageBodyReader 'readFrom' returns null #49

Closed
cowtowncoder opened this issue Apr 5, 2014 · 7 comments
Closed
Milestone

Comments

@cowtowncoder
Copy link
Member

(note: moved from https://github.com/FasterXML/jackson-jaxrs-json-provider/issues/27)


The readFrom() method in ProviderBase returns null when it encounters an empty stream. According to both the javadoc for MessageBodyReader, and JSR311, this is not allowed.

http://download.oracle.com/otndocs/jcp/jaxrs-1.1-mrel-eval-oth-JSpec/

In section 4.2.4:

When reading zero-length request entities, all implementation-supplied
MessageBodyReader implementations except the JAXB-related one MUST create a
corresponding Java object that represents zero-length data; they MUST NOT return
null. The implementation-supplied JAXB MessageBodyReader implementation MUST
throw a WebApplicationException with a client error response (HTTP 400) for zero-
length request entities.

And if creating an object representing the zero-length entity is impossible, the MessageBodyReader javadoc specifies that:

In case the entity input stream is empty, the reader
is expected to either return an instance representing a zero-length entity or throw
a {@link javax.ws.rs.core.NoContentException} in case no zero-length entity representation is
defined for the supported Java type.

Offending code in question on line 750:
ObjectReader reader = endpoint.getReader();
JsonParser jp = _createParser(reader, entityStream);

    // If null is returned, considered to be empty stream
    if (jp == null || jp.nextToken() == null) {
        return null;
    }
@cowtowncoder
Copy link
Member Author

(comment copied from the original bug)

Looks like the old behavior was specified in one of the drafts of the specification (and this was reported in old issue 17). Does seem to have changed in the published spec.

@cowtowncoder
Copy link
Member Author

Maybe introducing a DeserializationFeature.FAIL_ON_EMPTY_SOURCE (default false) would be an option?

@marceloverdijk
Copy link

+1 (subscribe)

@cowtowncoder
Copy link
Member Author

Hmmh. One nasty problem with NoContentException: it is only defined in JAX-RS 2.0. So I don't think it can actually be used as we still support 1.x version for various reasons.

So what would be suitable alternative? I assume JAX-RS 1.1 should have some suggestion here.

@cowtowncoder
Copy link
Member Author

One idea... maybe I can just dynamically locate the exception class if it's there.

@marceloverdijk
Copy link

Yes sounds reasonable.

M

Sent from my iPhone 5s

On 06 Apr 2014, at 06:53, Tatu Saloranta [email protected] wrote:

One idea... maybe I can just dynamically locate the exception class if it's there.


Reply to this email directly or view it on GitHub.

@cowtowncoder
Copy link
Member Author

Ok: Added JaxRSFeature.ALLOW_EMPTY_INPUT, which defaults to 'true' for backwards compatibility reasons. When disabled, error will be thrown, which should be properly translated: with JAX-RS 2.x will dynamically locate and use NoContentException; with 1.x just throws IOException with same error message.

@cowtowncoder cowtowncoder added this to the 2.4.0 milestone Apr 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants