How were you thinking to make it configurable?
Matt Mower wrote:
Matt Mower wrote:
Hi folks,
I'm using the Apache XML-RPC 1.2-b1 library to communicate with a process running on Frontier however the library seems to be improperly encoding doubles.
According to the spec[1] only standard decimal representation is supported:
At this time, only decimal point notation is allowed, a plus or a minus, followed by any number of numeric characters, followed by a period and any number of numeric characters.
However I am occasionally seeing results being passed using scientific notification:
<value><double>2.059538383036852E-4</double></value>
Did I report this to the right place?
I've done a little digging and the problem appears to be in:
org.apache.xmlrpc.XmlWriter#writeObject( Object obj )
where it does:
else if (obj instanceof Double || obj instanceof Float) { startElement("double"); write(obj.toString()); endElement("double"); }
My suggested fix is to add a DecimalFormat instance to the class (it appears to be thread safe so could be added as a static like dateTool) and use:
else if (obj instanceof Double || obj instanceof Float) { startElement("double"); write( decimalFormat.format( obj ) ); endElement("double"); }
I've made this fix to my local copy and, in my limited tests, it seems to work fine.
There is an issue about precision since you have to specify a pattern to the DecimalFormat. I rather arbitrarily used "0.0#######################" which was good enough for my purposes (i.e. I no longer get errors) but probably this is the kind of thing that should be configurable.
Any thoughts?