Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Object JsonParser.getNumberValueDeferred() method to allow for deferred decoding in some cases #902

Closed
cowtowncoder opened this issue Jan 28, 2023 · 0 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

cowtowncoder commented Jan 28, 2023

(note: alternative take on #893)

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.

@cowtowncoder 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
@cowtowncoder cowtowncoder added this to the 2.15.0 milestone Jan 29, 2023
cowtowncoder added a commit that referenced this issue Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant