IntervalOfTimeSerializer extends StdSerializer<IntervalOfTime> { @Override public void serialize(IntervalOfTime ivl, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { if (provider.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) { jgen.writeStartObject(); jgen.writeFieldName("low"); jgen.writeObject(ivl.getLow()); jgen.writeFieldName("high"); jgen.writeObject(ivl.getHigh()); jgen.writeEndObject(); } else { jgen.writeString(IntervalOfTimeFormat.print(ivl)); } } IntervalOfTimeSerializer(); @Override void serialize(IntervalOfTime ivl, JsonGenerator jgen, SerializerProvider provider);  }
@Test public void testSerialize() throws Exception { jsonMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); assertThat(jsonMapper.writeValueAsString(ivl), is("\"19750723000000.000..19750729235959.999\"")); }