Today, I can't adjust things in the background. I say I'm coming to a blog at this time. In fact, I write a blog to share with you. Although the content is very simple, there are a lot of Xiaobai now, so some people will use it. One is that I write complicated words and let Daniel see the bug, which is too embarrassing. I will write it after I practice again. Here is the code:
Gson is Google's official parsing tool, the usage is as follows
First write the Bean class
TestBean mainly makes a unified interface, one is to implement serialization, and the other is used to transform bean classes. I don't know if you can search for it.
public inteface TestBean extends Serializable{
}
public class BaseBean implement TestBean{
}
The above is the encapsulation of Bean, other beans must inherit BaseBean
Below is the analysis
public class GsonUtil<T extends BaseBean> implement Parser<T>{
private Class<? extends BaseBean> clazz;
public GsonUtil(Class<? extends BaseBean> clazz){
this.clazz = clazz;
}
@override
public T parse(String json){
return (T)new Gson().fromJson(json,clazz);
}
}
ok it's that simple
}