-
Notifications
You must be signed in to change notification settings - Fork 355
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
Throwing NoContentException when InputStream is empty #4275
Conversation
This PR proposes a solution which reconstitutes compliance with JAX-RS 2.1 with a two-step approach to detect an empty input stream:
As long as we allow this MBR to be used with other JAX-RS implementations (not just Jersey), we need this PR, and we need this two-step approach. An alternative solution could be to clearly restrict this MBR to work on Jersey only (e. g. by documentation or even technical checks), in which case we could leave out one of the two steps as we then know for sure the type of input stream Jersey will run this MBR with. |
Please see also jakartaee/rest#795. |
@spericas @chkal I assume this is the code location where you want the topic discussed in jakartaee/rest#795 to be handled (rather than the JAX-RS spec). :-) |
Is it possible to add a test checking the behaviour for an empty stream? |
media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java
Outdated
Show resolved
Hide resolved
media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java
Outdated
Show resolved
Hide resolved
480f3e6
to
4c6b2ac
Compare
Added unit test covering this issue with 4c6b2ac. |
b909908
to
69c1533
Compare
Since JAX-RS 2.1 an MBR must react upon an empty stream either with an empty instance or with NoContentException, but Jersey's JSON-B MBR does neither - it simply throws ProcessingException: "In case the entity input stream is empty, the reader is expected to either return a Java representation of a zero-length entity or throw a javax.ws.rs.core.NoContentException in case no zero-length entity representation is defined for the supported Java type." Signed-off-by: Markus KARG <[email protected]>
Signed-off-by: Markus KARG <[email protected]>
Signed-off-by: Markus KARG <[email protected]>
Signed-off-by: Maxim Nesen <[email protected]>
ed74d92
to
e0fa5ca
Compare
just another thought... previous comment was wrong :)
|
Cool optimization! 😎 If you are sure it is as safe and as fast I would be happy to accept your PR ontop! 👍 |
@mkarg, OK, I've submitted a PR to your branch :) |
Signed-off-by: Maxim Nesen <[email protected]>
Since JAX-RS 2.1 an MBR must react upon an empty stream either with an empty instance or with NoContentException, but Jersey's JSON-B MBR does neither - it simply throws ProcessingException:
"In case the entity input stream is empty, the reader is expected to either return a Java representation of a zero-length entity or throw a javax.ws.rs.core.NoContentException in case no zero-length entity representation is defined for the supported Java type."