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
JacksonMessageBodyProvider throws exception when post body is null #625
Comments
Can you post an example of the Resource method, a request being made (i.e. via |
Of course: https://gist.github.com/gedl/5e359a7cdf8d6f83b099 Dropwizard version 0.71 Thanks for helping. |
Added https://gist.github.com/gedl/5e359a7cdf8d6f83b099#file-workaround which is a workaround. Needs to be hooked to Jersey Hope it helps somebody else. |
This behaviour has been added (incidentally by me) in #433 (also see #232, #233, and #431) and is intentional. I think we should discuss whether this behaviour should be configurable (either throw a Maybe someone else wants to weigh in on this issue. |
I clearly have a clumsy fix, but I'm more worried about breaking the What do you think?
|
I think that the null check should only occur if the request method parameter is annotated with I've created #633 to address this issue. |
Good point. I vote for @NotNull as @Valid does not necessarly mean the G.
|
If you want to use parameters which may or may not be set, I suggest wrapping them in an |
I haven't carefully followed the whole thread, but on my experience at least with Jersey, @Valid on a resource method parameter does NOT throw any exception if the parameter is not provided. To insist that the parameter be provided, you have to add @NotNull . Doesn't that indicate that @Valid only applies when the object in question is non-null? I looked up the spec on the Hibernate site, but that is silent on the question of null objects when @Valid is used. |
So this doesn't seem to be simple at all…
Anything else to consider? |
I think this functionality is now provided by the Jersey upstream with Bean Validation Support. |
I did now run in to this problem as well. I'm migrating our system from Dropwizard 0.6.1 to 0.7.1 and now our log in doesn't work because our clients sends an empty json POST. Did you guys come up with a way around this by keeping legacy client support (that will continuously send empty json POSTs)? @joschi you mention Jersey's upstream, but it's not available in Dropwizard 0.7.1 is it? |
In case someone came here like me trying to resolve a similar issue and can't upgrade the dropwizard version to the latest immediately. I tried using @gedl workaround but it made the assumption that .available() would always return non-zero. I made a modification to just go ahead and copy the entity stream to a byte array regardless to ensure we truly know if anything is on the input stream. |
JacksonMessageBodyProvider in Dropwizard 0.6 allowed null post bodies. As a result, the resource methods would get a "default" instance (calling the default constructor) of the parameter type.
However in 0.7, JacksonMessageBodyProvider throws an exception and the resource method never gets called. Posting {} reverts to the old behaviour.
Because our application is now expecting the old behaviour (i.e. accepted null post bodies reverting to default constructors on resource methods) in multiple places (namely many client applications) changing all the calls is likely to be a nightmare.
Is there any way we can workaround this? Expected behaviour is to get null or an instance of the parameter created with the default constructor.
Thanks.
The text was updated successfully, but these errors were encountered: