GSON轉換成Long型變為科學計數法及時間格式轉換異常的解決方案


直接上工具類了,簡單實用

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

}



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM