UnixTimestampDeserializer extends JsonDeserializer<Calendar> { @Override public Calendar deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { long timestamp = p.getValueAsLong() * 1000; Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timestamp); return calendar; }  @Override Calendar deserialize(final JsonParser p,
                                final DeserializationContext ctxt);  }
@Test public void testGenericConstructor() throws Exception { Calendar c = Calendar.getInstance(); c.set(Calendar.MILLISECOND, 0); long unixTimestamp = c.getTimeInMillis() / 1000; String idBody = String.format("%s", unixTimestamp); JsonFactory f = new JsonFactory(); JsonParser preloadedParser = f.createParser(idBody); preloadedParser.nextToken(); JsonDeserializer deserializer = new UnixTimestampDeserializer(); Calendar deserialized = (Calendar) deserializer.deserialize(preloadedParser, mock(DeserializationContext.class)); assertEquals(c, deserialized); }
@Test public void deserialize() throws Exception { Calendar c = Calendar.getInstance(); c.set(Calendar.MILLISECOND, 0); long unixTimestamp = c.getTimeInMillis() / 1000; String idBody = String.format("%s", unixTimestamp); JsonFactory f = new JsonFactory(); JsonParser preloadedParser = f.createParser(idBody); preloadedParser.nextToken(); UnixTimestampDeserializer deserializer = new UnixTimestampDeserializer(); Calendar deserialized = (Calendar) deserializer.deserialize(preloadedParser, mock(DeserializationContext.class)); assertEquals(c, deserialized); }