LongConverter implements PropertyConverter<Long> { @Override public Long convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<long>", "MIN", "MIN_VALUE", "MAX", "MAX_VALUE"); if(value==null){ return null; } String trimmed = value.trim(); switch (trimmed.toUpperCase(Locale.ENGLISH)) { case "MIN_VALUE": case "MIN": return Long.MIN_VALUE; case "MAX_VALUE": case "MAX": return Long.MAX_VALUE; default: try { return Long.decode(trimmed); } catch(Exception e) { LOGGER.finest("Unable to parse Long createValue: " + value); return null; } } }  @Override Long 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(Long.class)).build(); LongConverter converter = new LongConverter(); converter.convert("", context); assertThat(context.getSupportedFormats()).contains("<long> (LongConverter)", "MIN_VALUE (LongConverter)", "MAX_VALUE (LongConverter)"); }