CustomDateDeserializer extends StdDeserializer<Date> { @Override public Date deserialize(JsonParser jsonparser, DeserializationContext context) throws IOException, JsonProcessingException { LocalDateTime ldtDate = this.deserializer.deserialize(jsonparser, context); return null==ldtDate ? null : Date.from(ldtDate.atZone(ZoneId.systemDefault()).toInstant()); } CustomDateDeserializer(); protected  CustomDateDeserializer(Class<?> vc); @Override Date deserialize(JsonParser jsonparser, DeserializationContext context);  }
@Test public void t1_deserialize() throws IOException { Mockito.when(this.jsonParser.getText()).thenReturn("1988-10-13T00:00:00.000Z"); final Date result = this.testee.deserialize(this.jsonParser, null); Mockito.verify(this.jsonParser, Mockito.times(1)).getText(); Assert.assertEquals(new GregorianCalendar(1988, Calendar.OCTOBER, 13).getTime(), result); }
@Test public void t1_deserializeBadDate() throws IOException { Mockito.when(this.jsonParser.getText()).thenReturn("02-11-2018"); this.thrown.expect(JsonParseException.class); this.thrown.expectMessage("Unparseable date: \"02-11-2018\". Supported format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); this.testee.deserialize(this.jsonParser, null); }