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":[]}
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":[]}
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?
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.