0

I am sending a request to a server and retrieving a JSON response in the format below. How do I convert it to Java format. Thanks in advance

{"customers":{"788488":77,"280460":78},"errors":[]}
Yasin Kaçmaz
  • 6,573
  • 5
  • 40
  • 58
David Kandie
  • 47
  • 1
  • 5

2 Answers2

4

If you want to use POJO classes checkout this website : JSON schema to pojo

Usage : Select source type JSON , and annotation style None

Also you can look my answer for information about converting json response to POJO with Gson, in this option select annotation style Gson : Convert JSON to POJO with Gson

More information : How to create a POJO?

Community
  • 1
  • 1
Yasin Kaçmaz
  • 6,573
  • 5
  • 40
  • 58
2

You can generate the java classes something like this:

public class Main {    
     private Customer customers;
     private List<Object> errors = new ArrayList<Object>();
     // getters/setters    
}

public class Customer {
     private Map<String, Object> additionalProperties = new HashMap<String, Object>();
     // getters/setters
}

Since, I do not know about what type error is, so can not really tell, what exactly it is. Now the received JSON (if follows the provided rules (i.e. naming conventions etc)) will be converted to the response in appropriate fields.

java8.being
  • 464
  • 3
  • 11