public
Type type = new ParameterizedTypeImpl(clazz);
List
return list;
}
private class ParameterizedTypeImpl implements ParameterizedType {
Class clazz;
public ParameterizedTypeImpl(Class clz) {
clazz = clz;
}
@Override
public Type[] getActualTypeArguments() {
return new Type[]{clazz};
}
@Override
public Type getRawType() {
return List.class;
}
@Override
public Type getOwnerType() {
return null;
}
}
public static T gsonToBean(String jsonString, Class beanClass) {
Gson gson = new Gson();
T bean = gson.fromJson(jsonString, beanClass);
return bean;
}
public static <T> List<T> gsonToBeanList(String jsonString, Class clazz) {
Gson gson = new Gson();
Type type = new ParameterizedTypeImpl(clazz);
List<T> list = gson.fromJson(jsonString, type);
return list;
}
public static <T> List<T> gsonToBeanList(String jsonString, Type type) {
Gson gson = new Gson();
List<T> list = gson.fromJson(jsonString, type);
return list;
}