PointInTimeSerializer extends StdSerializer<PointInTime> { @Override public void serialize(PointInTime t, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { if (provider.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) { jgen.writeStartArray(); jgen.writeNumber(t.getYear()); if (t.isMonthSet()) jgen.writeNumber(t.getMonth()); if (t.isDateSet()) jgen.writeNumber(t.getDate()); if (t.isHourSet()) jgen.writeNumber(t.getHour()); if (t.isMinuteSet()) jgen.writeNumber(t.getMinute()); if (t.isSecondSet()) jgen.writeNumber(t.getSecond()); if (t.isMillisecondSet()) jgen.writeNumber(t.getMillisecond()); jgen.writeEndArray(); } else { jgen.writeString(t.toString()); } } PointInTimeSerializer(); @Override void serialize(PointInTime t, JsonGenerator jgen, SerializerProvider provider);  }
@Test public void testSerialize() throws Exception { jsonMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); assertThat(jsonMapper.writeValueAsString(new PointInTime(1997, 1, 23)), is("\"19970123\"")); }