use of com.squareup.moshi.Rfc3339DateJsonAdapter in project moshi by square.
the class ReadAndWriteRfc3339Dates method run.
public void run() throws Exception {
Moshi moshi = new Moshi.Builder().add(Date.class, new Rfc3339DateJsonAdapter()).build();
JsonAdapter<Tournament> jsonAdapter = moshi.adapter(Tournament.class);
// The RFC3339 JSON adapter can read dates with a timezone offset like '-05:00'.
String lastTournament = "" + "{" + " \"location\":\"Chainsaw\"," + " \"name\":\"21 for 21\"," + " \"start\":\"2015-09-01T20:00:00-05:00\"" + "}";
System.out.println("Last tournament: " + jsonAdapter.fromJson(lastTournament));
// The RFC3339 JSON adapter always writes dates with UTC, using a 'Z' suffix.
Tournament nextTournament = new Tournament("Waterloo Classic", "Bauer Kitchen", newDate(2015, 10, 1, 20, -5));
System.out.println("Next tournament JSON: " + jsonAdapter.toJson(nextTournament));
}
Aggregations