@@ -2623,12 +2623,44 @@ protected void _copyCurrentContents(JsonParser p) throws IOException
2623
2623
/**
2624
2624
* Method for copying current {@link JsonToken#VALUE_NUMBER_FLOAT} value;
2625
2625
* overridable by format backend implementations.
2626
+ * Implementation checks
2627
+ * {@link JsonParser#getNumberType()} for declared type and uses matching
2628
+ * accessors: this may cause inexact conversion for some textual formats
2629
+ * (depending on settings). If this is problematic, use
2630
+ * {@lnik #_copyCurrentFloatValueExact} instead (note that doing so may add
2631
+ * overhead).
2626
2632
*
2627
2633
* @param p Parser that points to the value to copy
2628
2634
*
2629
2635
* @since 2.15
2630
2636
*/
2631
2637
protected void _copyCurrentFloatValue (JsonParser p ) throws IOException
2638
+ {
2639
+ NumberType t = p .getNumberType ();
2640
+ if (t == NumberType .BIG_DECIMAL ) {
2641
+ writeNumber (p .getDecimalValue ());
2642
+ } else if (t == NumberType .FLOAT ) {
2643
+ writeNumber (p .getFloatValue ());
2644
+ } else {
2645
+ writeNumber (p .getDoubleValue ());
2646
+ }
2647
+ }
2648
+
2649
+ /**
2650
+ * Method for copying current {@link JsonToken#VALUE_NUMBER_FLOAT} value;
2651
+ * overridable by format backend implementations.
2652
+ * Implementation ensures it uses most accurate accessors necessary to retain
2653
+ * exact value in case of possible numeric conversion: in practice this means
2654
+ * that {@link BigDecimal} is usually used as the representation accessed from
2655
+ * {@link JsonParser}, regardless of whether {@link Double} might be accurate
2656
+ * (since detecting lossy conversion is not possible to do efficiently).
2657
+ * If minimal overhead is desired, use {@link #_copyCurrentFloatValue} instead.
2658
+ *
2659
+ * @param p Parser that points to the value to copy
2660
+ *
2661
+ * @since 2.15
2662
+ */
2663
+ protected void _copyCurrentFloatValueExact (JsonParser p ) throws IOException
2632
2664
{
2633
2665
Number n = p .getNumberValueExact ();
2634
2666
if (n instanceof BigDecimal ) {
0 commit comments