ByteConverter implements PropertyConverter<Byte> { @Override public Byte convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(),"<byte>", "MIN_VALUE", "MIN", "MAX_VALUE", "MAX"); if(value==null){ return null; } String trimmed = value.trim(); switch(trimmed.toUpperCase(Locale.ENGLISH)){ case "MIN_VALUE": case "MIN": return Byte.MIN_VALUE; case "MAX_VALUE": case "MAX": return Byte.MAX_VALUE; default: try { return Byte.decode(trimmed); } catch(Exception e) { LOG.log(Level.FINEST, "Unparseable Byte: " + value); return null; } } }  @Override Byte 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(Byte.class)).build(); ByteConverter converter = new ByteConverter(); converter.convert("", context); assertThat(context.getSupportedFormats()).contains("<byte> (ByteConverter)", "MIN_VALUE (ByteConverter)", "MAX_VALUE (ByteConverter)"); }