@Test public void converterHandlesNullValueCorrectly() throws Exception { ConversionContext context = mock(ConversionContext.class); BigDecimalConverter converter = new BigDecimalConverter(); BigDecimal value = converter.convert("", context); assertThat(value).isNull(); }
@Override public BigDecimal convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<bigDecimal> -> new BigDecimal(String)"); if(value==null){ return null; } String trimmed = value.trim(); try{ return new BigDecimal(trimmed); } catch(Exception e){ LOG.finest("Parsing BigDecimal failed, trying BigInteger for: " + value); BigInteger bigInt = integerConverter.convert(value, ctx); if(bigInt!=null){ return new BigDecimal(bigInt); } LOG.finest("Failed to parse BigDecimal from: " + value); return null; } }
BigDecimalConverter implements PropertyConverter<BigDecimal> { @Override public BigDecimal convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<bigDecimal> -> new BigDecimal(String)"); if(value==null){ return null; } String trimmed = value.trim(); try{ return new BigDecimal(trimmed); } catch(Exception e){ LOG.finest("Parsing BigDecimal failed, trying BigInteger for: " + value); BigInteger bigInt = integerConverter.convert(value, ctx); if(bigInt!=null){ return new BigDecimal(bigInt); } LOG.finest("Failed to parse BigDecimal from: " + value); return null; } } }
BigDecimalConverter implements PropertyConverter<BigDecimal> { @Override public BigDecimal convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<bigDecimal> -> new BigDecimal(String)"); if(value==null){ return null; } String trimmed = value.trim(); try{ return new BigDecimal(trimmed); } catch(Exception e){ LOG.finest("Parsing BigDecimal failed, trying BigInteger for: " + value); BigInteger bigInt = integerConverter.convert(value, ctx); if(bigInt!=null){ return new BigDecimal(bigInt); } LOG.finest("Failed to parse BigDecimal from: " + value); return null; } }  }
BigDecimalConverter implements PropertyConverter<BigDecimal> { @Override public BigDecimal convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<bigDecimal> -> new BigDecimal(String)"); if(value==null){ return null; } String trimmed = value.trim(); try{ return new BigDecimal(trimmed); } catch(Exception e){ LOG.finest("Parsing BigDecimal failed, trying BigInteger for: " + value); BigInteger bigInt = integerConverter.convert(value, ctx); if(bigInt!=null){ return new BigDecimal(bigInt); } LOG.finest("Failed to parse BigDecimal from: " + value); return null; } }  @Override BigDecimal convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode(); }
BigDecimalConverter implements PropertyConverter<BigDecimal> { @Override public BigDecimal convert(String value, ConversionContext ctx) { ctx.addSupportedFormats(getClass(), "<bigDecimal> -> new BigDecimal(String)"); if(value==null){ return null; } String trimmed = value.trim(); try{ return new BigDecimal(trimmed); } catch(Exception e){ LOG.finest("Parsing BigDecimal failed, trying BigInteger for: " + value); BigInteger bigInt = integerConverter.convert(value, ctx); if(bigInt!=null){ return new BigDecimal(bigInt); } LOG.finest("Failed to parse BigDecimal from: " + value); return null; } }  @Override BigDecimal convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }