Created
May 29, 2011 01:02
-
-
Save yutax77/997371 to your computer and use it in GitHub Desktop.
How to deserialize generics class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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