标签:token tty new from @param tom rgb static public
public class GsonUtil { private static Gson gson = null; static { if (gson == null) { gson = new Gson(); } } private GsonUtil() { } /** * 对象转字符串 * @param o * @return */ public static String gsonToString(Object o){ return gson.toJson(o); } /** * 字符串转对象 * @param json * @param c * @param <T> * @return */ public static<T> T stringToBean(String json,Class<T> c){ return gson.fromJson(json,c); } /** * 字符串转list,list里是对象 * @param json * @param c * @param <T> * @return */ public static<T> List<T> stringToBeanList(String json, Class<T> c){ return gson.fromJson(json,new TypeToken<List<T>>(){}.getType()); } /** * 字符串转list,list里是map * @param json * @param <T> * @return */ public static<T> List<T> stringToMapList(String json){ return gson.fromJson(json,new TypeToken<List<Map<String,T>>>(){}.getType()); } /** * 字符串转map * @param json * @param <T> * @return */ public static<T> Map<String,T> stringToMap(String json){ return gson.fromJson(json,new TypeToken<Map<String,T>>(){}.getType()); } }
标签:token tty new from @param tom rgb static public
原文地址:https://www.cnblogs.com/zhangxiaofan/p/14330893.html