Gson 解析LocalDateTime
作者:
菜鸟考官 | 来源:发表于
2021-04-12 16:33 被阅读0次 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
本文链接:https://www.haomeiwen.com/subject/fapxlltx.html
网友评论