【发布时间】:2017-08-22 10:14:05
【问题描述】:
我在gwt 中有一个Person 类,并且我发送了一个Person 的实例,其中servlet 使用Gson 从服务器到客户端进行了转换。但在客户端似乎我不能使用Gson。从我在论坛上看到的内容看来,最好的方法是使用AutoBeans 将Json 再次转换为对象Person。
但是在AutoBeans 我只能使用一个接口。如果有人能帮我写,我将不胜感激。
我从服务器获取的json 示例并想再次转换为Person 类:
{"name":"aaa","family":"fff","username":"uuu","age":20,"phones":[{"id":0,"phoneNumber": "0911111"}],"亲戚":[null]}
public class Person implements Serializable {
private String name;
private String family;
private String username;
private int age;
private List<Phone> phones;
private List<Person> relatives;
public Person() {
}
public Person(String name, String family, String username, int age, List<Phone> phones, List<Person> relatives) {
this.name = name;
this.family = family;
this.username = username;
this.age = age;
this.phones = phones;
this.relatives = new ArrayList<Person>();
this.relatives = relatives;
}
public void addPhone(Phone p) {
phones.add(p);
}
public String getName() {
return this.name;
}
public String getFamily() {
return this.family;
}
public int getAge() {
return this.age;
}
public String getUsername() {
return this.username;
}
public List<Phone> getNumbers() {
return this.phones;
}
public List<Person> getRelatives() {
return this.relatives;
}
public String getAllNumbers() {
return Phone.convertPhonesToText(phones);
}
public static Person findPerson(List<Person> personList, String username) {
// .....
}
public static List<Person> convertTextToPersons(List<Person> personList, String personsText) {
// .....
}
public String convertPersonsToText() {
// ....
}
}
【问题讨论】:
标签: java gwt json-deserialization autobean