@Test public void testOptionalString() { TypeLiteral<List<String>> listOfStringTypeLiteral = new TypeLiteral<List<String>>() { }; ConversionContext context = new ConversionContext.Builder("testOptionalString", listOfStringTypeLiteral).build(); final Optional<String> result = new OptionalConverter().convert("astring", context); assertThat(result).isNotNull(); assertThat(result.isPresent()).isTrue(); assertThat(result.get()).isEqualTo("astring"); }
@Override public Optional convert(String value, ConversionContext ctx) { if(value==null){ return Optional.empty(); } try{ Type targetType = ctx.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return Optional.of(value); } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); return Optional.ofNullable(ctx.getConfiguration().adapt(converter)); }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } }
OptionalConverter implements PropertyConverter<Optional> { @Override public Optional convert(String value, ConversionContext ctx) { if(value==null){ return Optional.empty(); } try{ Type targetType = ctx.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return Optional.of(value); } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); return Optional.ofNullable(ctx.getConfiguration().adapt(converter)); }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } } }
OptionalConverter implements PropertyConverter<Optional> { @Override public Optional convert(String value, ConversionContext ctx) { if(value==null){ return Optional.empty(); } try{ Type targetType = ctx.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return Optional.of(value); } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); return Optional.ofNullable(ctx.getConfiguration().adapt(converter)); }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } }  }
OptionalConverter implements PropertyConverter<Optional> { @Override public Optional convert(String value, ConversionContext ctx) { if(value==null){ return Optional.empty(); } try{ Type targetType = ctx.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return Optional.of(value); } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); return Optional.ofNullable(ctx.getConfiguration().adapt(converter)); }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } }  @Override Optional convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode(); }
OptionalConverter implements PropertyConverter<Optional> { @Override public Optional convert(String value, ConversionContext ctx) { if(value==null){ return Optional.empty(); } try{ Type targetType = ctx.getTargetType().getType(); ParameterizedType pt = (ParameterizedType) targetType; if(String.class.equals(pt.getActualTypeArguments()[0])){ return Optional.of(value); } ConvertQuery converter = new ConvertQuery(value, TypeLiteral.of(pt.getActualTypeArguments()[0])); return Optional.ofNullable(ctx.getConfiguration().adapt(converter)); }catch(Exception e){ throw new ConfigException("Error evaluating config createValue.", e); } }  @Override Optional convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }