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:

https://github.com/gkopff/gson-javatime-serialisers

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

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -