JiBX
  1. JiBX
  2. JIBX-293

BigDecimal values sometimes serialize to exponential notation (like "-1.23E-10")

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor 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 :
      0

      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()

        Activity

        Hide
        Dennis Sosnoski added a comment -

        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.

        Show
        Dennis Sosnoski added a comment - 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.
        Hide
        Dennis Sosnoski added a comment -

        Added and documented BigDecimal.java5 conversion to work around broken JDK compatibility. This cannot be used by default without breaking JiBX's compatibility for older JDK users, but is available as an option for those using JDK 1.5 and later.

        Show
        Dennis Sosnoski added a comment - Added and documented BigDecimal.java5 conversion to work around broken JDK compatibility. This cannot be used by default without breaking JiBX's compatibility for older JDK users, but is available as an option for those using JDK 1.5 and later.

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Richard Neish
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: