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