Did you try using the validation annotations?
I think that adding Validators will make illegal input to return bad
request.

‫בתאריך יום ב׳, 18 במאי 2020 ב-18:35 מאת ‪Robert Di Falco‬‏
<‪[email protected]‬‏>:‬

> My server responds with status 500 instead of 400 when invalid JSON is
> sent to me dropwizard service. We tracked it down to Immutables throwing an
> IllegalStateException which Jackson then wraps as an
> InvalidDefinitionException which of course ends up triggering this line in
> the Dropwizard JsonProcessingExceptionMapper.
>
> if (exception instanceof JsonGenerationException || exception instanceof 
> InvalidDefinitionException) {
>     return super.toResponse(exception); // LoggingExceptionMapper will log 
> exception
> }
>
>
> Is there a simple way around this? A configuration or some such so that I
> properly return the status of 400? The only thing we can come up with is
> writing our own Exception Mapper and not using the drop wizard supplied
> one. But it seems heavy handed.
>
> public class ImmutablesJsonProcessingExceptionMapper extends 
> JsonProcessingExceptionMapper {
>   @Override
>   public Response toResponse(JsonProcessingException exception) {
>     if (exception instanceof InvalidDefinitionException) {
>       exception = new JsonParseException((JsonParser) null, null, exception);
>     }
>
>     return super.toResponse(exception);
>   }
> }
>
>
>
>  Thanks for any input.
>
> R.
>
> --
> You received this message because you are subscribed to the Google Groups
> "dropwizard-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/dropwizard-user/2b89feea-abb3-44e8-a5ff-8b620a78cfdf%40googlegroups.com
> <https://groups.google.com/d/msgid/dropwizard-user/2b89feea-abb3-44e8-a5ff-8b620a78cfdf%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Look for me on Facebook <https://www.facebook.com/usulkies>, Twitter
<https://twitter.com/usulkies>or LinkedIn
<http://www.linkedin.com/in/uziel-sulkies-41338a2b>.

-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dropwizard-user/CAM4HiRbzZSbJnVT2y55iuKTACg6B9XMsq4tes83UnodEGQUGMw%40mail.gmail.com.

Reply via email to