I\'m using Jersey\'s integrated Jackson processing to transform incoming JSON to a POJO, e.g.:
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response newCus
I was finally able to work around this problem by implementing an ExceptionMapper
to catch the UnrecognizedPropertyException
thrown by Jackson and map it to a 400 Bad Request response:
@Provider
public class UnrecognizedPropertyExceptionMapper implements ExceptionMapper
{
@Override
public Response toResponse(UnrecognizedPropertyException exception)
{
return Response
.status(Response.Status.BAD_REQUEST)
.entity( "'" + exception.getUnrecognizedPropertyName() + "' is an unrecognized field.")
.type( MediaType.TEXT_PLAIN)
.build();
}
}