如何使用Gson序列化和反序列化Java 8的java.time类型?[已关闭]
2022-09-01 17:39:55
这里有一个Java 8库:
以下是 Maven 详细信息(查看中心以获取最新版本):
<dependency>
<groupId>com.fatboyindustrial.gson-javatime-serialisers</groupId>
<artifactId>gson-javatime-serialisers</artifactId>
<version>1.1.1</version>
</dependency>
下面是一个如何驾驶它的简单示例:
Gson gson = Converters.registerOffsetDateTime(new GsonBuilder()).create();
SomeContainerObject original = new SomeContainerObject(OffsetDateTime.now());
String json = gson.toJson(original);
SomeContainerObject reconstituted = gson.fromJson(json, SomeContainerObject.class);