Dropwizard example giving 400 error when creating new resource Dropwizard example giving 400 error when creating new resource json json

Dropwizard example giving 400 error when creating new resource


To get helpful message regarding 400 error, register this on jersey:

environment.jersey().register(new JsonProcessingExceptionMapper(true));

It will give more detailed message on 400 response, useful for debugging.


A little background: Dropwizard utilizes Jersey, and Jersey is what ultimately gives you back the 400 Bad Request response, probably along with a vague and laconic message.

In order to see exactly what did bother Jackson (which in turn bothered Jersey), I started out by sending a blank (empty) JSON object and see whether it was accepted (it did - and all the fields in the POJO where zero-initialized). Then I started to add fields, sending each such object along, until I reached the problematic field (in my case it was a boolean field which should have been a Boolean).

I think I can spot two difficulties in your POJO (the Document class):

  1. The getters/setters should be annotated with @JsonProperty.

  2. Try to change Id's type to Long (nullable long). If you are concerned about getting a null in that field, you can have the getter return a zero or any default value instead.


I faced the same issue. The errors are suppressed and not passed properly in the stack trace. What I did was to add a try catch around the function. Then added a debugger point in the exception. I was able to figure out the exact reason.

You could try something like this.

@POST@UnitOfWorkpublic Document createDocument(Document document) throws Exception{....}

Add debugger points in the Exception class. You will find out the exact reason of the parsing failure.

Hope I am clear and it helps!