Skip to content

Instantly share code, notes, and snippets.

@yutax77
Created May 29, 2011 01:02
Show Gist options
  • Save yutax77/997371 to your computer and use it in GitHub Desktop.
Save yutax77/997371 to your computer and use it in GitHub Desktop.
How to deserialize generics class
import flexjson.JSONDeserializer;
public class Person<T extends Detail> {
private String name;
private int age;
private T detail;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public T getDetail() {
return detail;
}
public void setDetail(T detail) {
this.detail = detail;
}
public static Person<PersonDetail> fromJson(String json){
return new JSONDeserializer<Person<PersonDetail>>()
.use(null, Person.class)
.use("detail", PersonDetail.class)
.deserialize(json);
}
}
public static <T extends Detail> Person<T> fromJson(String json, Class<T> target){
return new JSONDeserializer<Person<T>>()
.use(null, Person.class)
.use("detail", target)
.deserialize(json);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment