Yes: suppress the default exception mapper, and provide one like this (in
this case we tell the client what it did wrong, but you could log instead
or in addition to):
import java.util.LinkedHashMap;
import java.util.Map;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import com.fasterxml.jackson.core.JsonProcessingException;
@Provider
public class JsonInformativeExceptionMapper implements ExceptionMapper<
JsonProcessingException> {
@Override
public Response toResponse(JsonProcessingException exception) {
Map<String,Object> entity = new LinkedHashMap<>();
entity.put("code", 400);
{
String message = exception.getOriginalMessage();
if (message != null) {
int pos = message.indexOf('\n');
if (pos == -1) {
pos = message.indexOf(" at [Source");
}
if (pos > 0) {
message = message.substring(0, pos);
}
entity.put("message", message);
}
}
if (exception.getLocation() != null) {
entity.put("location", String.format("line %d, column %d",
exception.getLocation().getLineNr(),
exception.getLocation().getColumnNr()));
}
return Response.status(Status.BAD_REQUEST)
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(entity)
.build();
}
}
On Thursday, March 30, 2017 at 10:27:07 AM UTC-4, Rohit Verma wrote:
>
> Hi All,
>
> Is there a way to find out which field of my pojo object caused* Unable
> to process JSON *error, or is there a way to log jackson exception which
> cause this error
>
>
--
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].
For more options, visit https://groups.google.com/d/optout.