Question

How can i convert a json objet to java bean(MainBean) of following type

class MainBean{
private int id;
private SubBean sBean;
}  
class SubBean{
private String name;
private List<DBean> dBean;
}
Was it helpful?

Solution

There are alot of libraries that can do it.
For exanple, you can do it using Google-Gson

MainBean bean = new Gson().fromJson(yourJsonAsString, MainBean.class); 

JSON like this will be converted well

{"id" : 1, "sBean" : {"name" : "beanname", "dBean" : []}}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top