@@ -50,19 +50,39 @@ public enum StreamReadCapability
50
50
UNTYPED_SCALARS (false ),
51
51
52
52
/**
53
- * Capability that indicates that data format may report floats
54
- * as a non-exact {@link com.fasterxml.jackson.core.JsonParser.NumberType},
55
- * due to prohibitively expensive parsing costs of determing the precision
56
- * upfront. For example, JSON numbers may be reported as
57
- * {@link com.fasterxml.jackson.core.JsonParser.NumberType#DOUBLE}
58
- * even if they would not fit into a 64-bit double without precision
59
- * loss. Methods like {@link JsonParser#getNumberValueExact()} or
60
- * {@link JsonParser#getValueAsString()} still report values without
53
+ * Capability that indicates whether data format supports reporting of
54
+ * accurate floating point values (with respect to reported numeric type,
55
+ * {@link com.fasterxml.jackson.core.JsonParser.NumberType#DOUBLE}) or not.
56
+ * This usually depends on whether format stores such values natively
57
+ * (as IEEE binary FP formats for {@code java.lang.Float} and {@code java.lang.Double};
58
+ * using some other value preserving presentation for {@code java.math.BigDecimal})
59
+ * or not: most binary formats do, and most textual formats do not (at least for
60
+ * {@code Float} and {@code Double}, specifically).
61
+ *<p>
62
+ * In case of JSON numbers (as well as for most if not all textual formats),
63
+ * all floating-point numbers are represented simply by decimal (10-base)
64
+ * textual representation and can only be represented accurately using
65
+ * {@link java.math.BigDecimal}. But for performance reasons they may be
66
+ * (depending on settings) be exposed as {@link java.lang.Double}s (that is,
67
+ * {@link com.fasterxml.jackson.core.JsonParser.NumberType#DOUBLE}).
68
+ * Note that methods like {@link JsonParser#getNumberValueExact()},
69
+ * {@link JsonParser#getValueAsString()} and
70
+ * {@link JsonParser#getDecimalValue()} report values without
61
71
* precision loss.
62
- *
63
- * Capability is false for text formats JSON, but true for binary formats
72
+ *<p>
73
+ * The main intended use case is to let non-Jackson code to handle cases
74
+ * where exact accuracy is necessary in a way that handling does not incur
75
+ * unnecessary conversions across different formats: for example, when reading
76
+ * binary format, simple access is essentially guaranteed to expose value exactly
77
+ * as encoded by the format (as {@code float}, {@code double} or {@code BigDecimal}),
78
+ * whereas for textual formats like JSON it is necessary to access value explicitly
79
+ * as {@code BigDecimal} using {@code JsonParser#getDecimalValue}.
80
+ *<p>
81
+ * Capability is false for text formats like JSON, but true for binary formats
64
82
* like Smile, MessagePack, etc., where type is precisely and inexpensively
65
- * signaled by a tag.
83
+ * indicated by format.
84
+ *
85
+ * @since 2.14
66
86
*/
67
87
EXACT_FLOATS (false )
68
88
;
0 commit comments