@Override public Integer convertToAvro(String value) { return StringUtils.isEmpty(value) ? null : ParserUtils.parseToInteger(ParserUtils.transformNumberString(value, thousandsSepChar, decimalSepChar), isDecode()); } }
@Test public void testParseToInteger() throws Exception { assertNull(ParserUtils.parseToInteger(null, true)); assertThat(10, equalTo(ParserUtils.parseToInteger("010", false))); assertThat(8, equalTo(ParserUtils.parseToInteger("010", true))); assertThat(10, equalTo(ParserUtils.parseToInteger("10", false))); assertThat(10, equalTo(ParserUtils.parseToInteger("10", true))); try { ParserUtils.parseToInteger("0X10", false); fail("Except get NumberFormatException"); } catch (Exception e) { assertEquals(NumberFormatException.class, e.getClass()); LOG.debug("Except exception:" + e.getMessage()); } assertThat(16, equalTo(ParserUtils.parseToInteger("0X10", true))); assertThat(74565, equalTo(ParserUtils.parseToInteger("0X12345", true))); }