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

JacksonJsonProvider MessageBodyReader 'readFrom' returns null #49

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

Comments

@cowtowncoder
Copy link
Member

@cowtowncoder cowtowncoder commented Apr 5, 2014

(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 cowtowncoder reopened this Apr 5, 2014
@cowtowncoder
Copy link
Member Author

@cowtowncoder cowtowncoder commented Apr 5, 2014

(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

@cowtowncoder cowtowncoder commented Apr 5, 2014

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

@marceloverdijk
Copy link

@marceloverdijk marceloverdijk commented Apr 5, 2014

+1 (subscribe)

@cowtowncoder
Copy link
Member Author

@cowtowncoder cowtowncoder commented Apr 6, 2014

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

@cowtowncoder cowtowncoder commented Apr 6, 2014

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

@marceloverdijk
Copy link

@marceloverdijk marceloverdijk commented Apr 6, 2014

Yes sounds reasonable.

M

Sent from my iPhone 5s

On 06 Apr 2014, at 06:53, Tatu Saloranta notifications@github.com 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

@cowtowncoder cowtowncoder commented Apr 7, 2014

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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.