Reading numbers (and other types) as string
See original GitHub issueCurrently parsing strings to numbers can be enabled by isStringified
or @stringified
, but the possibility to enable parsing any value as a String (be it numbers or booleans, etc) could be useful. One case is when parsing json documents from MongoDB where there is no schema on write and users add ids as strings, doubles, longs (for the same field, e.g. id) only to be truncated (if needed) to integers in the end.
To the extent of my knowledge in jsoniter-scala there is currently no possibility to do this without writing custom codec and it takes a lot of coding on user’s side.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Data Types in Programming: Numbers, Strings and Others
One of the most widely used data types is a string. A string consists of one or more characters, which can include letters,...
Read more >Conversions Between Strings and Other Types - Visual Basic
Conversion of Numbers to Strings Format automatically uses the appropriate symbols according to the Regional Options settings specified in the ...
Read more >10. Numbers, Characters, and Strings - gigamonkeys
All rational numbers are "canonicalized" as they're read--that's why 10 and 20/2 are both read as the same number, as are 3/4 and...
Read more >How to read number as a String type and return an output in ...
I'd use enum like this: public enum MyNumber { ONE(1), TWO(2), THREE(3); private final int value; MyNumber(int value){ this.value = value; } ...
Read more >Data Types and Type Conversion
How can I convert one type to another? Objectives. Explain key differences between ... Explain key differences between numbers and character strings.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Lets for simplicity assume that 64 bits will be enough for internal binary representation of ID.
Than the definition of the
ID
type and a codec for it can be like in the code snippet below:It should print the following output:
Do you have some example of implementation of such custom codec?
Any other options for representation of IDs in Mongo is rather everything - Longs, Strings, UUIDs, compound types, etc (but in my case id is a number but can be persisted as int/long/double/stringified number…)
You are right, the following representations are equal in my case.