UnixTimestampSerializer extends JsonSerializer<Calendar> { @Override public void serialize(final Calendar value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException { gen.writeNumber(value.getTimeInMillis() / 1000); }  @Override void serialize(final Calendar value,
                          final JsonGenerator gen,
                          final SerializerProvider serializers);  }
@Test public void testGenericConstructor() throws Exception { Calendar c = Calendar.getInstance(); long unixTimestamp = c.getTimeInMillis() / 1000; JsonSerializer serializer = new UnixTimestampSerializer(); JsonGenerator generator = mock(JsonGenerator.class); serializer.serialize(c, generator, null); verify(generator).writeNumber(unixTimestamp); }
@Test public void deserialize() throws Exception { Calendar c = Calendar.getInstance(); long unixTimestamp = c.getTimeInMillis() / 1000; UnixTimestampSerializer serializer = new UnixTimestampSerializer(); JsonGenerator generator = mock(JsonGenerator.class); serializer.serialize(c, generator, null); verify(generator).writeNumber(unixTimestamp); }