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
I'm working on a C++ application which exchanges data with a Java app using JSON. On the Java side, they used a currency class. The data is written as floating point value in the JSON. We handle this by reading it as a double and then converting it to pennies. And visa versa when going the other way. This works, but the use of double for currency annoys me.
I've been debating possible solutions. The most flexible would be to add the ability to "ReadAsString" and WriteAsString, which would treat a numeric value as a string with the restriction that the value must ultimately be numeric.
Perhaps there is already a way to do this, in which case, educate me.
The text was updated successfully, but these errors were encountered:
Currently RapidJSON does not support this feature. The feature you request may be like "validating JSON numbers but not converting them to doubles", and vice versa.
I am not sure whether this feature is a common need. If so, we can consider adding this in the coming versions. My idea for that is adding a parse flag, related SAX events and DOM APIs.
A simple solution is to serialize the currency as JSON string type instead of number type. And then you do the format validation and conversion in the application side.
I agree that the currency values should have been sent as strings. Alas, the team we are interacting with can't change due to their existing clients. (Another solution, which we were doing in our own code, is to store currency as 64-bit integers and apply a denominator.)
I agree that this may not be a common need. However, I'll still ponder various solutions.
I'm working on a C++ application which exchanges data with a Java app using JSON. On the Java side, they used a currency class. The data is written as floating point value in the JSON. We handle this by reading it as a double and then converting it to pennies. And visa versa when going the other way. This works, but the use of double for currency annoys me.
I've been debating possible solutions. The most flexible would be to add the ability to "ReadAsString" and WriteAsString, which would treat a numeric value as a string with the restriction that the value must ultimately be numeric.
Perhaps there is already a way to do this, in which case, educate me.
The text was updated successfully, but these errors were encountered: