标签:ati ali rom parameter 对象 bbb turn json family
public static <T> T obj2Obj(Object origin, Class<T> clazz) {
Gson gson = new Gson(); if(origin == null) { return null; } return gson.fromJson(gson.toJson(origin), clazz); }
//把一个list对象转成含有相同属性的另外一个list public static <C extends Collection<T>, T> C obj2List(Object origin, Class<T> type) {
Gson gson = new Gson();
if(origin == null) { return null; } Type[] argumentTypes = new Type[]{type}; Type parameterizedType = ParameterizedTypeImpl.make(List.class, argumentTypes, null); return gson.fromJson(gson.toJson(origin), parameterizedType); }
public static <T> T obj2Obj(@C("待转对象")Object origin, @C("转成的类")Class<T> clazz) {
if(origin == null) {
return null;
}
return gson.fromJson(gson.toJson(origin), clazz);
}
public static <C extends Collection<T>, T> C obj2List(Object origin, Class<T> type) {
if(origin == null) {
return null;
}
Type[] argumentTypes = new Type[]{type};
Type parameterizedType = ParameterizedTypeImpl.make(List.class, argumentTypes, null);
return gson.fromJson(gson.toJson(origin), parameterizedType);
}
标签:ati ali rom parameter 对象 bbb turn json family
原文地址:https://www.cnblogs.com/coderising/p/11219530.html