Is there a standard implementation for a GSON Joda Time serialiser?

后端 未结 6 1885
梦毁少年i
梦毁少年i 2020-12-25 11:27

I\'m using GSON to serialise some object graphs to JSON. These objects graphs use Joda Time entities (DateTime, LocalTime etc).

The top Go

6条回答
  •  感情败类
    2020-12-25 12:25

    I've decided to roll my own open source one - you can find it here:

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

    Here's the Maven details (check central for the latest version):

    
      com.fatboyindustrial.gson-jodatime-serialisers
      gson-jodatime-serialisers
      1.6.0
    
    

    And here's a quick example of how you drive it:

    Gson gson = Converters.registerDateTime(new GsonBuilder()).create();
    SomeContainerObject original = new SomeContainerObject(new DateTime());
    
    String json = gson.toJson(original);
    SomeContainerObject reconstituted = gson.fromJson(json, SomeContainerObject.class);
    

提交回复
热议问题