@@ -40,11 +40,18 @@ private BigDecimalParser() {}
4040 * @throws NumberFormatException
4141 */
4242 public static BigDecimal parse (String valueStr ) {
43- if (valueStr .length () < 500 ) {
44- return new BigDecimal (valueStr );
43+ try {
44+ if (valueStr .length () < 500 ) {
45+ return new BigDecimal (valueStr );
46+ }
47+ // workaround https://github.com/FasterXML/jackson-databind/issues/4694
48+ return JavaBigDecimalParser .parseBigDecimal (valueStr );
49+
50+ // 20-Aug-2022, tatu: Although "new BigDecimal(...)" only throws NumberFormatException
51+ // operations by "parseBigDecimal()" can throw "ArithmeticException", so handle both:
52+ } catch (ArithmeticException | NumberFormatException e ) {
53+ throw _parseFailure (e , valueStr );
4554 }
46- // workaround https://github.com/FasterXML/jackson-databind/issues/4694
47- return JavaBigDecimalParser .parseBigDecimal (valueStr );
4855 }
4956
5057 /**
@@ -118,7 +125,8 @@ public static BigDecimal parseWithFastParser(final String valueStr) {
118125 */
119126 public static BigDecimal parseWithFastParser (final char [] ch , final int off , final int len ) {
120127 try {
121- return JavaBigDecimalParser .parseBigDecimal (ch , off , len );
128+ // workaround https://github.com/FasterXML/jackson-databind/issues/4694
129+ return JavaBigDecimalParser .parseBigDecimal (new String (ch , off , len ));
122130 } catch (ArithmeticException | NumberFormatException e ) {
123131 throw _parseFailure (e , ch , off , len );
124132 }
@@ -167,7 +175,8 @@ private static String _getValueDesc(final char[] array, final int offset, final
167175 }
168176
169177 private static String _generateExceptionMessage (final String valueToReport , final String desc ) {
170- return String .format ("Value %s can not be deserialized as `java.math.BigDecimal`, reason: %s" ,
178+ return String .format ("Value %s cannot be deserialized as `java.math.BigDecimal`, reason: %s" ,
171179 valueToReport , desc );
172180 }
181+
173182}
0 commit comments