val gsonBuilder = GsonFactory.getSingletonGson().newBuilder()
gsonBuilder.registerTypeAdapter(
LocalDateTime::class.java,
JsonDeserializer { json: JsonElement, type: Type?, context: JsonDeserializationContext? ->
val instant = json.asJsonPrimitive.asLong
LocalDateTime(instant)
} as JsonDeserializer<LocalDateTime>
).registerTypeAdapter(
LocalDateTime::class.java,
JsonSerializer { time: LocalDateTime, type: Type?, context: JsonSerializationContext? ->
JsonPrimitive(time.toDateTime(DateTimeZone.UTC).millis)
} as JsonSerializer<LocalDateTime?>).create()
GsonUtils.setGsonDelegate(gsonBuilder.create())
Gson 解析LocalDateTime
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 打造終極MVP+Retrofit2+okhttp3+Rxjava2網(wǎng)絡(luò)請求,開發(fā)實用,簡約,由于篇幅字數(shù)原因 本...
- json解析--Gson使用和json解析類詳解 1.對于標準的json數(shù)據(jù)格式,可以使用Google 提供的用來...
- 寫AdapterFactory類,實現(xiàn)TypeAdapterFactory接口 在有錯誤的字段加上@JsonAda...
- 創(chuàng)建查看https://blog.csdn.net/u013005791/article/details/7290...
- GSOn作用:把需要解析的數(shù)據(jù)(字符串)轉(zhuǎn)換成對象或把對象轉(zhuǎn)換為 字符串 使用JSONView工具:把需要解析的數(shù)...