例如
public class A {
private List<B> list;
public List<B> getList() {
return list;
}
public void setList(List<B> list) {
this.list = list;
}
public static void main(String[] args) {
JSONObject json = JSONObject
.fromObject("{list:[{name:'Tom',age:999}]}");
A j = (A) JSONObject.toBean(json, A.class);
System.out.println(j);
}
}
public class B {
private int age;
private String name;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
执行之后 A对象的List里装的不是B对象 而是MorphDynaBean?
如何让json对象直接封装成需要的bean对象?