In Dropwizard I use @Valid annotations for my resource methods:
public class Address {
@NotNull
String street
...
}
@Path("/address")
@Produces(MediaType.APPLICATION_JSON)
public class AddressResource {
@POST
public MyResponse addAddress(@Valid Address address) {
if (address == null) {
throw new WebApplicationException("address was null");
}
...
}
}
On application start I register a custom WebApplicationExceptionMapper
which handles WebApplicationExceptions
. Thus, for addresses with the value null, the exception is thrown and handled in the mapper which generates a useful response. However, if the address is not null but street
is, Dropwizard automatically generates a response and sends it to the client (which I dislike).
How do I interfere this response so that in the end it is also handled by the mapper?