FloatConverter implements PropertyConverter<Float> { @Override public Float convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<float>", "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 Float.POSITIVE_INFINITY; case "NEGATIVE_INFINITY": return Float.NEGATIVE_INFINITY; case "NAN": return Float.NaN; case "MIN_VALUE": case "MIN": return Float.MIN_VALUE; case "MAX_VALUE": case "MAX": return Float.MAX_VALUE; default: try { return Float.valueOf(trimmed); } catch(Exception e){ LOG.finest("Parsing of float as floating number failed, trying parsing integral" + " number/hex instead..."); } Integer val = integerConverter.convert(trimmed, ctx); if(val!=null) { return val.floatValue(); } LOG.finest("Unparseable float createValue: " + trimmed); return null; } }  @Override Float 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(Float.class)).build(); FloatConverter converter = new FloatConverter(); converter.convert("", context); assertThat(context.getSupportedFormats()).contains("<float> (FloatConverter)", "MIN_VALUE (FloatConverter)", "MAX_VALUE (FloatConverter)"); }