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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 打造终极MVP+Retrofit2+okhttp3+Rxjava2网络请求,开发实用,简约,由于篇幅字数原因 本...
- json解析--Gson使用和json解析类详解 1.对于标准的json数据格式,可以使用Google 提供的用来...
- 写AdapterFactory类,实现TypeAdapterFactory接口 在有错误的字段加上@JsonAda...
- GSOn作用:把需要解析的数据(字符串)转换成对象或把对象转换为 字符串 使用JSONView工具:把需要解析的数...