DoubleConverter implements PropertyConverter<Double> { @Override public Double convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<double>", "MIN", "MIN_VALUE", "MAX", "MAX_VALUE", "POSITIVE_INFINITY", "NEGATIVE_INFINITY", "NAN"); if(value==null){ return null; } String trimmed = value.trim(); switch (trimmed.toUpperCase(Locale.ENGLISH)) { case "POSITIVE_INFINITY": return Double.POSITIVE_INFINITY; case "NEGATIVE_INFINITY": return Double.NEGATIVE_INFINITY; case "NAN": return Double.NaN; case "MIN_VALUE": case "MIN": return Double.MIN_VALUE; case "MAX_VALUE": case "MAX": return Double.MAX_VALUE; default: try { return Double.valueOf(trimmed); } catch (Exception e) { LOG.finest("Parsing of double as floating number failed, trying parsing integral" + " number/hex instead..."); } Long val = integerConverter.convert(trimmed, ctx); if(val!=null){ return val.doubleValue(); } return null; } }  @Override Double convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(Double.class)).build(); DoubleConverter converter = new DoubleConverter(); converter.convert("", context); assertThat(context.getSupportedFormats()).contains("<double> (DoubleConverter)", "MIN_VALUE (DoubleConverter)", "MAX_VALUE (DoubleConverter)"); }