@@ -652,9 +652,15 @@ protected final Float _parseFloat(JsonParser p, DeserializationContext ctxt)
652
652
if (_checkTextualNull (ctxt , text )) {
653
653
return (Float ) getNullValue (ctxt );
654
654
}
655
- try {
656
- return NumberInput .parseFloat (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER ));
657
- } catch (IllegalArgumentException iae ) { }
655
+ // 09-Dec-2023, tatu: To avoid parser having to validate input, pre-validate:
656
+ if (NumberInput .looksLikeValidNumber (text )) {
657
+ p .streamReadConstraints ().validateFPLength (text .length ());
658
+ try {
659
+ return NumberInput .parseFloat (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER ));
660
+ } catch (IllegalArgumentException iae ) {
661
+ if (true ) throw new Error ();
662
+ }
663
+ }
658
664
return (Float ) ctxt .handleWeirdStringValue (_valueClass , text ,
659
665
"not a valid `Float` value" );
660
666
}
@@ -751,10 +757,13 @@ protected final Double _parseDouble(JsonParser p, DeserializationContext ctxt) t
751
757
if (_checkTextualNull (ctxt , text )) {
752
758
return (Double ) getNullValue (ctxt );
753
759
}
754
- p .streamReadConstraints ().validateFPLength (text .length ());
755
- try {
756
- return _parseDouble (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER ));
757
- } catch (IllegalArgumentException iae ) { }
760
+ // 09-Dec-2023, tatu: To avoid parser having to validate input, pre-validate:
761
+ if (NumberInput .looksLikeValidNumber (text )) {
762
+ p .streamReadConstraints ().validateFPLength (text .length ());
763
+ try {
764
+ return _parseDouble (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER ));
765
+ } catch (IllegalArgumentException iae ) { }
766
+ }
758
767
return (Double ) ctxt .handleWeirdStringValue (_valueClass , text ,
759
768
"not a valid `Double` value" );
760
769
}
@@ -843,30 +852,31 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
843
852
return Double .NaN ;
844
853
}
845
854
try {
846
- if (!_isIntNumber (text )) {
855
+ if (_isIntNumber (text )) {
856
+ p .streamReadConstraints ().validateIntegerLength (text .length ());
857
+ if (ctxt .isEnabled (DeserializationFeature .USE_BIG_INTEGER_FOR_INTS )) {
858
+ return NumberInput .parseBigInteger (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
859
+ }
860
+ long value = NumberInput .parseLong (text );
861
+ if (!ctxt .isEnabled (DeserializationFeature .USE_LONG_FOR_INTS )) {
862
+ if (value <= Integer .MAX_VALUE && value >= Integer .MIN_VALUE ) {
863
+ return Integer .valueOf ((int ) value );
864
+ }
865
+ }
866
+ return value ;
867
+ }
868
+ // 09-Dec-2023, tatu: To avoid parser having to validate input, pre-validate:
869
+ if (NumberInput .looksLikeValidNumber (text )) {
847
870
p .streamReadConstraints ().validateFPLength (text .length ());
848
871
if (ctxt .isEnabled (DeserializationFeature .USE_BIG_DECIMAL_FOR_FLOATS )) {
849
872
return NumberInput .parseBigDecimal (
850
873
text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
851
874
}
852
- return Double .valueOf (
853
- NumberInput .parseDouble (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER )));
854
- }
855
- p .streamReadConstraints ().validateIntegerLength (text .length ());
856
- if (ctxt .isEnabled (DeserializationFeature .USE_BIG_INTEGER_FOR_INTS )) {
857
- return NumberInput .parseBigInteger (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
858
- }
859
- long value = NumberInput .parseLong (text );
860
- if (!ctxt .isEnabled (DeserializationFeature .USE_LONG_FOR_INTS )) {
861
- if (value <= Integer .MAX_VALUE && value >= Integer .MIN_VALUE ) {
862
- return Integer .valueOf ((int ) value );
863
- }
875
+ return NumberInput .parseDouble (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER ));
864
876
}
865
- return Long .valueOf (value );
866
- } catch (IllegalArgumentException iae ) {
867
- return ctxt .handleWeirdStringValue (_valueClass , text ,
868
- "not a valid number" );
869
- }
877
+ } catch (IllegalArgumentException iae ) { }
878
+ return ctxt .handleWeirdStringValue (_valueClass , text ,
879
+ "not a valid number" );
870
880
}
871
881
872
882
/**
@@ -966,10 +976,12 @@ public BigInteger deserialize(JsonParser p, DeserializationContext ctxt) throws
966
976
// note: no need to call `coerce` as this is never primitive
967
977
return getNullValue (ctxt );
968
978
}
969
- p .streamReadConstraints ().validateIntegerLength (text .length ());
970
- try {
971
- return NumberInput .parseBigInteger (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
972
- } catch (IllegalArgumentException iae ) { }
979
+ if (_isIntNumber (text )) {
980
+ p .streamReadConstraints ().validateIntegerLength (text .length ());
981
+ try {
982
+ return NumberInput .parseBigInteger (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
983
+ } catch (IllegalArgumentException iae ) { }
984
+ }
973
985
return (BigInteger ) ctxt .handleWeirdStringValue (_valueClass , text ,
974
986
"not a valid representation" );
975
987
}
@@ -1036,10 +1048,13 @@ public BigDecimal deserialize(JsonParser p, DeserializationContext ctxt)
1036
1048
// note: no need to call `coerce` as this is never primitive
1037
1049
return getNullValue (ctxt );
1038
1050
}
1039
- p .streamReadConstraints ().validateFPLength (text .length ());
1040
- try {
1041
- return NumberInput .parseBigDecimal (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
1042
- } catch (IllegalArgumentException iae ) { }
1051
+ // 09-Dec-2023, tatu: To avoid parser having to validate input, pre-validate:
1052
+ if (NumberInput .looksLikeValidNumber (text )) {
1053
+ p .streamReadConstraints ().validateFPLength (text .length ());
1054
+ try {
1055
+ return NumberInput .parseBigDecimal (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
1056
+ } catch (IllegalArgumentException iae ) { }
1057
+ }
1043
1058
return (BigDecimal ) ctxt .handleWeirdStringValue (_valueClass , text ,
1044
1059
"not a valid representation" );
1045
1060
}
0 commit comments