CustomLocalDateTimeSerializer extends StdSerializer<LocalDateTime> { @Override public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializerProvider) { try { gen.writeString(formatter.format(value)); } catch (IOException e) { throw new JsonParsingException(e); } } CustomLocalDateTimeSerializer();  CustomLocalDateTimeSerializer(Class<LocalDateTime> t); @Override void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializerProvider);  }
@Test public void t1_serialize() throws IOException { final LocalDate date = LocalDate.of(1988, 10, 13); final LocalDateTime dateTime = LocalDateTime.of(date, LocalTime.NOON); Mockito.doNothing().when(this.gen).writeString(Mockito.anyString()); this.testee.serialize(dateTime, gen, null); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); Mockito.verify(this.gen).writeString(captor.capture()); Assert.assertEquals("1988-10-13T12:00:00.000Z", captor.getValue()); }
@Test public void t1_serializeBadValue() throws IOException { final LocalDate date = LocalDate.of(1988, 10, 13); final LocalDateTime dateTime = LocalDateTime.of(date, LocalTime.NOON); Mockito.doThrow(new IOException()).when(this.gen).writeString(Mockito.anyString()); this.thrown.expect(JsonParsingException.class); this.testee.serialize(dateTime, gen, null); }