CBOR Parser

19 views
Skip to first unread message

TheCrisbros15

unread,
Jan 9, 2020, 10:17:16 AM1/9/20
to jackson-user
It seems to me the token VALUE_NUMBER_FLOAT handles both Floats and Doubles.... and that’s all well and good.
Now, how would one read in the token as either a double or float? I see there’s methods for each, but ones bigger than the other and I want to be efficient. Did I miss a method in the java doc?

Thanks in advance.

TheCrisbros15

unread,
Jan 9, 2020, 11:01:18 AM1/9/20
to jackson-user
It seems after some more digging I have answered my own question. Sorry for possibly wasting your time. I missed the getNumberType method.... I knew I overlooked something. I’ll wait longer next time.

Tatu Saloranta

unread,
Jan 9, 2020, 1:24:21 PM1/9/20
to jackson-user
On Thu, Jan 9, 2020 at 8:01 AM TheCrisbros15 <crisb...@gmail.com> wrote:
It seems after some more digging I have answered my own question. Sorry for possibly wasting your time. I missed the getNumberType method.... I knew I overlooked something. I’ll wait longer next time.

Glad you found it even before I had a chance to suggest it! No problem at all wrt asking: that's why this group is for.

There is also `getNumberValue()`, I think, for general "it's a number". And `getXxxValue()` methods handle coercions wherever applicable.
For what it is worth, not distinguishing `float` vs `double` is for legacy reasons: distinction can not usually be made for JSON given its textual representation. But binary-backed formats do keep track of physical representation, and it can be accessed the way you found (getNumberType()).

-+ Tatu +-
 

--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/528ade61-a0f3-4d02-b523-d25bb10d8105%40googlegroups.com.

TheCrisbros15 .

unread,
Jan 10, 2020, 10:07:35 AM1/10/20
to jackso...@googlegroups.com
That makes perfect sense. If I’m being honest, I’m still relatively new to Java, I come from a C++ background and I’m still learning some syntax and Java jargon.

Sooner or later, I’ll feel comfortable enough to contribute to this open source library. If allowed of course, not sure how that works either. 

Thanks a million, 
CD


On Thursday, January 9, 2020, Tatu Saloranta <tsalo...@gmail.com> wrote:
On Thu, Jan 9, 2020 at 8:01 AM TheCrisbros15 <crisb...@gmail.com> wrote:
It seems after some more digging I have answered my own question. Sorry for possibly wasting your time. I missed the getNumberType method.... I knew I overlooked something. I’ll wait longer next time.

Glad you found it even before I had a chance to suggest it! No problem at all wrt asking: that's why this group is for.

There is also `getNumberValue()`, I think, for general "it's a number". And `getXxxValue()` methods handle coercions wherever applicable.
For what it is worth, not distinguishing `float` vs `double` is for legacy reasons: distinction can not usually be made for JSON given its textual representation. But binary-backed formats do keep track of physical representation, and it can be accessed the way you found (getNumberType()).

-+ Tatu +-
 

--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAGrxA245USEb%3D7Vm7SDhhJi3oji1vFK57cjO0TNaN6mHTjo1kw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages