@@ -1769,6 +1769,10 @@ public void writeNumber(String encodedValue) throws IOException
1769
1769
1770
1770
// Let's see if it's integral or not
1771
1771
int i = neg ? 1 : 0 ;
1772
+ if (i >= len ) {
1773
+ _writeIntegralNumber (encodedValue , neg );
1774
+ return ;
1775
+ }
1772
1776
while (true ) {
1773
1777
char c = encodedValue .charAt (i );
1774
1778
if (c > '9' || c < '0' ) {
@@ -1791,22 +1795,25 @@ protected void _writeIntegralNumber(String enc, boolean neg) throws IOException
1791
1795
// let's do approximate optimization
1792
1796
try {
1793
1797
if (len <= 9 ) {
1794
- writeNumber (Integer .parseInt (enc ));
1798
+ // Avoid exception from empty String
1799
+ if (len > 0 ) {
1800
+ writeNumber (Integer .parseInt (enc ));
1801
+ }
1795
1802
} else if (len <= 18 ) {
1796
1803
writeNumber (Long .parseLong (enc ));
1797
1804
} else {
1798
- writeNumber (new BigInteger (enc ));
1805
+ writeNumber (NumberInput . parseBigInteger (enc , false ));
1799
1806
}
1800
- } catch ( NumberFormatException e ) {
1801
- throw new JsonGenerationException ( "Invalid String representation for Number ('" + enc
1802
- + "'); can not write using Smile format" , this );
1803
- }
1807
+ return ;
1808
+ } catch ( NumberFormatException e ) { }
1809
+ throw new JsonGenerationException ( "Invalid String representation for Number ('" + enc
1810
+ + "'); can not write using Smile format" , this );
1804
1811
}
1805
1812
1806
1813
protected void _writeDecimalNumber (String enc ) throws IOException
1807
1814
{
1808
1815
try {
1809
- writeNumber (NumberInput .parseBigDecimal (enc ));
1816
+ writeNumber (NumberInput .parseBigDecimal (enc , false ));
1810
1817
} catch (NumberFormatException e ) {
1811
1818
throw new JsonGenerationException ("Invalid String representation for Number ('" +enc
1812
1819
+"'); can not write using Smile format" , this );
0 commit comments