How to serialize and deserialize Java 8's java.time types with Gson? -
i'm using gson serialise object graphs json. these objects graphs use new java 8 java.time entities (zoneddatetime, offsetdatetime, localtime etc).
i've found library joda time serialisers here - there equivalent library jdk java.time classes?
(this person had no luck efforts use gson java.time - , question remains unanswered).
there's java 8 library here:
here's maven details (check central latest version):
<dependency> <groupid>com.fatboyindustrial.gson-javatime-serialisers</groupid> <artifactid>gson-javatime-serialisers</artifactid> <version>1.1.1</version> </dependency> and here's quick example of how drive it:
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);
Comments
Post a Comment