直接上工具类了,简单实用

public class GsonUtils {
    private static Gson gson = null;
static {
if (gson == null) {
gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd HH:mm:ss")
.setLongSerializationPolicy(LongSerializationPolicy.STRING)
.create();
}
}

public static String gsonString(Object object) {
String gsonString = null;
if (gson != null) {
gsonString = gson.toJson(object);
}
return gsonString;
}
    public static <T> List<T> gsonToList(String gsonString, Class<T> cls) {
List<T> list = null;
if (gson != null) {
list = gson.fromJson(gsonString, new TypeToken<List<T>>() {
}.getType());
}
return list;
}

}


相关文章:

  • 2022-12-23
  • 2021-12-02
  • 2021-10-31
  • 2021-04-14
  • 2022-12-23
  • 2021-07-06
  • 2021-12-08
猜你喜欢
  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案