The problem seems to be the two nested <item> tags. When renaming the second
to <item2> everything works.

Unfortunately I do not have access to the XML serialization and therefore
cannot change the XML layout.

Ideas would be greatly appreciated.





Villemos wrote:
> 
> I'm new to XStream and XML to POJO conversion, so this problem is properly
> quite simple and stupid.
> 
> I have the following XML string;
> 
> <response>
>   <status_code>0</status_code>
>   <result>
>     <item>
>       <fieldset>General information</fieldset>
>       <description>General document information</description>
>       <fields>
>         <item>
>           <name>Document Author</name>
>           <value>John Doe</value>
>         </item>
>         <item>
>           <name>Reference ID</name>
>           <value>OSMV-OPMT-LOGI-RP-11-1402</value>
>         </item>
>       </fields>
>     </item>
>   </result>
> </response>
> 
> 
> And have created the following classes;
> 
> @XStreamAlias("response")
> public class Metadata {
> 
>       public String status_code = "";
>       
>       @XStreamAlias("result") 
>       public List<MetadataItem> result = new ArrayList<MetadataItem>();
> }
> 
> 
> @XStreamAlias("item")
> public class MetadataItem {
> 
>       public String fieldset = "";
>       public String description = "";
>       
>       @XStreamAlias("fields")
>       public List<MetadataField> fields = new ArrayList<MetadataField>();
> }
> 
> 
> @XStreamAlias("item")
> public class MetadataField {
> 
>       public String name = "";
>       public String value = "";
> }
> 
> 
> 
> 
> Running the following junit tests fails misserably;
> 
> public class MetadataTest extends TestCase {
> 
>       public void testConvert() {
>               String testString = ...
> 
>               Metadata metadata = new Metadata();
>               XStream xstream = new XStream();
>               xstream.processAnnotations(MetadataField.class);
>               xstream.processAnnotations(MetadataItem.class);
>               xstream.processAnnotations(Metadata.class);             
>               xstream.fromXML(testString, metadata);
>         }
> }
> 
> 
> 
> 
> The trace is shown below. I dont understand the error message; It looks
> like its in the MetadataField:name conversion that something goes wrong,
> but thats a String. How can a CannotResolveClassException be thrown?
> 
> 
> 
> com.thoughtworks.xstream.converters.ConversionException: name : name :
> name : name
> ---- Debugging information ----
> message             : name : name
> cause-exception     :
> com.thoughtworks.xstream.mapper.CannotResolveClassException
> cause-message       : name : name
> class               : com.logica.oam.ktree.converters.Metadata
> required-type       : com.logica.oam.ktree.converters.MetadataItem
> path                : /response/result/item/fields/item/name
> line number         : 1
> -------------------------------
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:88)
>       at
> com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:55)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:75)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:59)
>       at
> com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:77)
>       at
> com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:68)
>       at
> com.thoughtworks.xstream.converters.collections.CollectionConverter.unmarshal(CollectionConverter.java:61)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:81)
>       at
> com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:55)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:75)
>       at
> com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:234)
>       at
> com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:206)
>       at
> com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:150)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:81)
>       at
> com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:55)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:75)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:59)
>       at
> com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:77)
>       at
> com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:68)
>       at
> com.thoughtworks.xstream.converters.collections.CollectionConverter.unmarshal(CollectionConverter.java:61)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:81)
>       at
> com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:55)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:75)
>       at
> com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:234)
>       at
> com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:206)
>       at
> com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:150)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:81)
>       at
> com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:55)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:75)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:59)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:142)
>       at
> com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:33)
>       at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:931)
>       at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:917)
>       at com.thoughtworks.xstream.XStream.fromXML(XStream.java:889)
>       at com.thoughtworks.xstream.XStream.fromXML(XStream.java:879)
>       at
> com.logica.oam.ktree.converters.MetadataTest.testConvert(MetadataTest.java:37)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:597)
>       at junit.framework.TestCase.runTest(TestCase.java:168)
>       at junit.framework.TestCase.runBare(TestCase.java:134)
>       at junit.framework.TestResult$1.protect(TestResult.java:110)
>       at junit.framework.TestResult.runProtected(TestResult.java:128)
>       at junit.framework.TestResult.run(TestResult.java:113)
>       at junit.framework.TestCase.run(TestCase.java:124)
>       at junit.framework.TestSuite.runTest(TestSuite.java:232)
>       at junit.framework.TestSuite.run(TestSuite.java:227)
>       at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
>       at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>       at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>       at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>       at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>       at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException:
> name : name
>       at
> com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:62)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:71)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:86)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:87)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
>       at
> com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:52)
>       at
> com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.determineType(AbstractReflectionConverter.java:318)
>       at
> com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:196)
>       at
> com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:150)
>       at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:81)
>       ... 54 more
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Getting-CannotResolveClassException-in-simple-XML2POJO-example-tp33308266p33310167.html
Sent from the xstream - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to