You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Accessing numeric value from JsonParser can be done either using typed accessors (getLongValue()) or using generic Number JsonParser.getNumberValue(). But in both of these cases access forces decoding of the actual numeric value.
But there are cases where it would be nice to only get actual Number if it has already been decoded; otherwise return String representation of the number.
Although there is no super nice way in Java to support "either" type, I think in this case it is fine to simply indicate type as Object and let caller do type-casting: main initial user will be TokenBuffer class in jackson-databind; and it will further use integer-or-floating-point distinction (wrt JsonParser.currentToken()) to figure out possible types.
Base implementation in JsonParser, for backwards compatibility, should be to simple call getNumberValue(), return that: subtypes that support deferred parsing then need to override this.
The text was updated successfully, but these errors were encountered:
cowtowncoder
changed the title
Add Object JsonParser.getNumberDeferred() method to allow for deferred decoding in some cases
Add Object JsonParser.getNumberValueDeferred() method to allow for deferred decoding in some cases
Jan 28, 2023
(note: alternative take on #893)
Accessing numeric value from
JsonParser
can be done either using typed accessors (getLongValue()
) or using genericNumber JsonParser.getNumberValue()
. But in both of these cases access forces decoding of the actual numeric value.But there are cases where it would be nice to only get actual
Number
if it has already been decoded; otherwise returnString
representation of the number.Although there is no super nice way in Java to support "either" type, I think in this case it is fine to simply indicate type as
Object
and let caller do type-casting: main initial user will beTokenBuffer
class injackson-databind
; and it will further use integer-or-floating-point distinction (wrtJsonParser.currentToken()
) to figure out possible types.Base implementation in
JsonParser
, for backwards compatibility, should be to simple callgetNumberValue()
, return that: subtypes that support deferred parsing then need to override this.The text was updated successfully, but these errors were encountered: