XStream
  1. XStream
  2. XSTR-540

JettisonMappedXMLDriver needs to take a Configuration object to use SimpleConverter in Jettison 1.1-SNAPSHOT to quote numeric strings

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: 1.4
    • Component/s: Converters
    • Labels:
      None

      Description

      There's a "feature"/issue (http://jira.codehaus.org/browse/JETTISON-36) that I introduced into Jettison project version 1.0.1 > where the JSON converter will attempt to convert numeric values in Java to numeric literals in JSON. The trouble is JSON uses 64 bit floating point values to represent numeric values. So if you have a very large long value, when that "literal" is converted into Javascript it will lose precision.

      To fix this Jettison allows you to specify a SimpleConverter that will quote numeric values. The trouble is the JettisonMappedXMLDriver passes in an empty Configuration so I needed to add a constructor that passes in a Configuration so that I could specify SimpleConverter. (I included the patch)

      Here's what I changed in JettisonMappedXMLDriver (I've also included the SVN patch text file):
      public JettisonMappedXmlDriver()

      { this(new Configuration(new HashMap())); }

      public JettisonMappedXmlDriver(final Configuration config)

      { mof = new MappedXMLOutputFactory(config); mif = new MappedXMLInputFactory(config); convention = new MappedNamespaceConvention(config); }

      Here's how I'm using it:

      private static XStream getXstream()

      { //return new XStream(new JettisonMappedXmlDriver()); StringWriter strWriter = new StringWriter(); Configuration config = new Configuration(); config.setTypeConverter(new SimpleConverter()); JettisonMappedXmlDriver xmlDriver = new JettisonMappedXmlDriver(config); return new XStream(xmlDriver); }

      My pom.xml is as follows:
      <dependency>
      <groupId>com.thoughtworks.xstream</groupId>
      <version>1.3.2-SNAPSHOT</version>
      <artifactId>xstream</artifactId>
      </dependency>
      <dependency>
      <groupId>org.codehaus.jettison</groupId>
      <artifactId>jettison</artifactId>
      <version>1.1-SNAPSHOT</version>
      </dependency>

      I've also attached a unit test to validate that the JettisonMappedXMLDriver will surround numeric literals with quotes when using the SimpleConverter otherwise not. Jettison may want to reevaluate how the type conversion works, possibly force it to be surrounded by quotes if it's a 64 bit long value, or if it's guranteed that the value is larger than the largest integer value that can be represented by a 64 bit float without possibly losing precision (which I believe is anything past the 2^31 -1).

        People

        • Assignee:
          Jörg Schaible
          Reporter:
          Doug Daniels
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: