@Test public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Duration.class)).build(); DurationConverter converter = new DurationConverter(); converter.convert("", context); assertThat(context.getSupportedFormats()).contains("PT20M34S (DurationConverter)"); }
@Override public Duration convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), Duration.of(1234, ChronoUnit.SECONDS).toString()); if(value==null){ return null; } try { return Duration.parse(value); }catch(Exception e){ LOG.log(Level.FINEST, e, () -> "Cannot parse Duration: " + value); return null; } }
DurationConverter implements PropertyConverter<Duration> { @Override public Duration convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), Duration.of(1234, ChronoUnit.SECONDS).toString()); if(value==null){ return null; } try { return Duration.parse(value); }catch(Exception e){ LOG.log(Level.FINEST, e, () -> "Cannot parse Duration: " + value); return null; } } }
DurationConverter implements PropertyConverter<Duration> { @Override public Duration convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), Duration.of(1234, ChronoUnit.SECONDS).toString()); if(value==null){ return null; } try { return Duration.parse(value); }catch(Exception e){ LOG.log(Level.FINEST, e, () -> "Cannot parse Duration: " + value); return null; } }  }
DurationConverter implements PropertyConverter<Duration> { @Override public Duration convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), Duration.of(1234, ChronoUnit.SECONDS).toString()); if(value==null){ return null; } try { return Duration.parse(value); }catch(Exception e){ LOG.log(Level.FINEST, e, () -> "Cannot parse Duration: " + value); return null; } }  @Override Duration convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode(); }
DurationConverter implements PropertyConverter<Duration> { @Override public Duration convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), Duration.of(1234, ChronoUnit.SECONDS).toString()); if(value==null){ return null; } try { return Duration.parse(value); }catch(Exception e){ LOG.log(Level.FINEST, e, () -> "Cannot parse Duration: " + value); return null; } }  @Override Duration convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }