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