SerializationUtils { public static Object toObject(String json) throws JsonException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.serializeNulls(); gsonBuilder.registerTypeAdapter(Object.class, new NaturalGsonDeserializer()); Gson gson = gsonBuilder.create(); return gson.fromJson(json, Object.class); } private  SerializationUtils(); @SuppressWarnings("unchecked") static Map<String, Object> fromJson(String json); static Object toObject(String json); static String toJson(Object o); static Class<?> getResultingClass(Object o); static Class<?> getResultingClass(String json);  }
@Test public void testDates_can_deserialize_legacy_date_format() throws JsonException { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); Object deserializedDate = SerializationUtils.toObject("\"" + format.format(date) + "\""); assertEquals(Date.class, deserializedDate.getClass()); assertTrue(date.after((Date)deserializedDate)); assertTrue(date.getTime() - ((Date)deserializedDate).getTime() < 1000L); }