Skip to content

Commit debf306

Browse files
committed
Start work on #984 (alas, need to do incrementally to merge to 3.x)
1 parent 0e8db3b commit debf306

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/main/java/com/fasterxml/jackson/core/JsonGenerator.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,12 +2623,44 @@ protected void _copyCurrentContents(JsonParser p) throws IOException
26232623
/**
26242624
* Method for copying current {@link JsonToken#VALUE_NUMBER_FLOAT} value;
26252625
* 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).
26262632
*
26272633
* @param p Parser that points to the value to copy
26282634
*
26292635
* @since 2.15
26302636
*/
26312637
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
26322664
{
26332665
Number n = p.getNumberValueExact();
26342666
if (n instanceof BigDecimal) {

0 commit comments

Comments
 (0)