XStream
  1. XStream
  2. XSTR-442

array class attributes corrupt JSON using JettisonMappedXmlDriver unless they are the last class attribute

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.2.2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • JDK version and platform:
      sun 1.5 for windows

      Description

      Serializing a class that has an array as an attrubute creates invalid JSON that wont reload into original Java class. It seems to misplace the } at the end of the array data in the generated JSON text, see below.

      {"customer":{"ids":

      {"string":["1","2","3","4"],"name":"david","postCode":"gu27 8uu"}

      }}

      BTW if you use the default XML driver all works fine.

      In the attached class if the ids attribute of the testCustomer class is the last attribute then all works fine if not it produces the following error :

      Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: name : name
      ---- Debugging information ----
      message : name : name
      cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
      cause-message : name : name
      class : json.test.TestCustomer
      required-type : [Ljava.lang.String;
      path : /customer/ids/name
      line number : -1
      -------------------------------
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:63)
      at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
      at com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.unmarshallField(AnnotationReflectionConverter.java:66)
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:188)
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:125)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
      at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117)
      at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:29)
      at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:846)
      at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:833)
      at com.thoughtworks.xstream.XStream.fromXML(XStream.java:781)
      at com.thoughtworks.xstream.XStream.fromXML(XStream.java:773)
      at json.test.Test.JSONToJava(Test.java:22)
      at json.test.Test.main(Test.java:30)
      Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: name : name
      at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:49)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:76)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:60)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:76)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:26)
      at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:34)
      at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:62)
      at com.thoughtworks.xstream.converters.collections.ArrayConverter.unmarshal(ArrayConverter.java:44)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
      ... 16 more

        Issue Links

          People

          • Assignee:
            Jörg Schaible
            Reporter:
            david wilson
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: