首页 > 其他 > 详细

GSON转换成Long型变为科学计数法及时间格式转换异常的解决方案

时间:2019-08-16 13:05:40      阅读:874      评论:0      收藏:0      [点我收藏+]
直接上工具类了,简单实用

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;
}

}


GSON转换成Long型变为科学计数法及时间格式转换异常的解决方案

原文:https://www.cnblogs.com/xuzhujack/p/11363007.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!