How to debug "Unable to process JSON" error, while calling my web-service using Postman?

Bhavya :

I have created a Web Service using Dropwizard. This is my POJO, which has almost 25 fields -

public class HelloWorld {
@NotEmpty
private String foo;
@NotEmpty
private String bar;
@NotEmpty
private String baz;
.. 
.. 

public HelloWorld() {
}

public UserRegistration(String foo, String bar, String baz,....)
{
 this.foo = foo;
 this.bar = bar;
 this.baz = baz;
 ..
 ..
 ..
}

public String getfoo() {
 return foo;
}

public String getbar() {
 return bar;
}

public String getbaz() {
 return baz;
}
public void setfoo(String foo) {
 this.foo = foo;
}

public void setbar(String bar) {
 this.bar = bar;
}
public void setbaz(String baz) {
 this.baz = baz;
}

}

Now when I am trying to call my API using postman, which uses my POJO - body :-

{
      "Foo": "a",
      "bar": "b",
      "baz": "c",
       ..
       ..
 }

I get the following response :

{
"code": 400,
"message": "Unable to process JSON"
}

I have referred to the following links :

I understand that Jackson is not able to convert this JSON to my POJO, due to some fields, but error message is not showing the culprit.

So can someone give me a way to debug this error in an efficient manner??

Technologies using:-

  • Dropwizard
  • Jersey
  • Jackson for serialization/deserialization
Opster Elasticsearch Ninja :

As mentioned by user @ahoxha, there is already some mismatch in your POJO and JSON payload, but as you don't have DEBUG log enabled for JSON processing class of Jackson library, you receive a generic error message without the mention of fields which caused this error.

To debug this, Enable DEBUG logging for Jackson JSON processing exception class, by adding below to your logging configuration.

io.dropwizard.jersey.jackson.JsonProcessingExceptionMapper: DEBUG

This should give you the detailed information, which field and why(name mismatch or type mismatch with JSON) it was not able to convert JSON to your POJO.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=141191&siteId=1