Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.1
-
Fix Version/s: 1.2
-
Labels:None
-
Environment:When consuming JSON produced messages in a web browser through (firefox, IE)
-
Number of attachments :
Description
I created an issue in the XStream project describing an issue with 64 bit Java long values losing precision when converting to javascript 64 bit float. I was able to work around it by changing the XStream API to accept the JETTISON SimpleConverter.
http://jira.codehaus.org/browse/XSTR-541
"The normal conversion of string values to JSON attempts to convert values to numeric values, but this is problematic for numeric values like 64 bit Long's when converted to Javascript, they are converted to 64 bit floating point values, so values larger than I believe 2^51 or something like that can lose precision.
We can use the SimpleConverter and I put in an issue into XStream to ensure that users can configure the JettisonMappedXMLDriver, but even in the default behavior of Jettison we probably shouldn't allow numeric values that are larger than can be converted into 64 bit double precision floating point (although I guess that's a javascript specific limitation, and maybe Javascript can check that when it's evaluating and if the numeric value doesn't match what the string field was it would fail, but I'm not sure that's really easy to change).
Here's the XStream patch with the issue, the solution right now is to simply use the SimpleConverter.
http://jira.codehaus.org/browse/XSTR-540 "
There was discussion on the mailing list to push this over to the Jettison developers:
http://thread.gmane.org/gmane.comp.java.xstream.user/5495/focus=5500
"Despite the fact that Jettison's SimpleConverter is not yet released, it's
nothing we can really use by default. A lot of people would be surprised if
any long/Long is suddenly provided as String. However, you might open an
issue for Jettison, that they automatically keep the value as String if the
long value exceed the JavaScript value range, because it is Jettison that
internally transforms the input of XStream (resp. the StAX writer's output)
into an integer value."
Would it be possible for JETTISON to detect a value is larger than what can be represented in Javascript's 64-bit double value and convert it to a string? I guess the issue with that is Javascript is not the only consumer of JSON messages, and it would be strange to see some values as strings and some as numeric literals, so it might be best to leave up to configuration.
We have encountered this issue using RESTEasy, and I'd argue that it is a blocker, not minor. An example:
Marshalled value on first request:
{"demoBean":{"name":"aName", "value":999999999999999999 } }Eval the bean:
demoBean : { name : 'aName', value : 1000000000000000000 }If the consumer then changes 'name' and saves the bean back to the server, value is modified as well.
I can imagine a couple of potential fixes for this.
Modify org.codehaus.jettison.mapped.DefaultConverter:
Another possible fix:
Check the System properties for a user-specified classpath to use for the TypeConverter
Thanks,
Geoff Granum