Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: JiBX 1.1.6
-
Fix Version/s: JiBX 1.2.2
-
Component/s: core
-
Labels:None
-
Environment:Window XP / CentOS Linux 5.2
Java version "1.6.0_10-rc"
-
Number of attachments :
Description
I have a binding file with mappings from a BigDecimal value to an XML element of type xsd:decimal. Under some circumstances the value produced by the default serializer is a number in exponential notation (like "-1.23E-10") and the resulting XML fails XML validation.
The workaround is to provide a custom serializer for java.math.BigDecimal that uses BigDecimal.toPlainString() instead of BigDecimal.toString().
See http://java.sun.com/javase/6/docs/api/java/math/BigDecimal.html#toString()
I find it very difficult to accept this as a JiBX bug when the issue is a non-backward-compatible change in the public Java APIs (in JDK 1.5, when Sun changed the format returned by toString() and added the new toPlainString() alternative). There's unfortunately no way I can see of handling this cleanly, since the toPlainString() method doesn't exist in older Java APIs. Even defining a different serializer as an option is difficult, since the code would need to be present in JiBX binding and runtime to call the toPlainString() method, meaning they wouldn't be compatible with older JVMs. I'll see what I can come up with.
It's ironic that the Java public APIs are riddled with absurd numbers of deprecated methods which have been present since version 1.0.X and continue to be supported in the latest JDKs in order to maintain backward compatibility, but Sun then intentionally changes a working public API in this manner. Whoever authorized this change should be banned from any involvement with Java.