LocalDateConverter implements PropertyConverter<LocalDate> { @Override public LocalDate convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), LocalDate.now().toString()); if(value==null){ return null; } try{ return LocalDate.parse(value); }catch(Exception e){ LOG.log(Level.FINEST, e, () -> "Cannot parse LocalDate: " + value); return null; } }  @Override LocalDate convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void convert() throws Exception { LocalDateConverter conv = new LocalDateConverter(); LocalDate value = conv.convert("2007-12-03", context); assertThat(LocalDate.parse("2007-12-03")).isEqualTo(value); value = conv.convert("foo", context); assertThat(value).isNull(); }
@Test public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(LocalDate.class)).build(); LocalDateConverter converter = new LocalDateConverter(); converter.convert("", context); assertThat(context.getSupportedFormats().toString()).contains(" (LocalDateConverter)"); }