Details
-
Type: Bug
-
Status: Closed
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.2.2
-
Component/s: None
-
Labels:None
-
JDK version and platform:Sun 1.5.0_x for Windows
Description
Hi everybody,
I tried to serialize and deserialize the following class structure:
public class TypeA
{ private String attrA = "testA"; }public class TypeB extends TypeA
{ private String attrB = "testB"; }public class TypeC extends TypeB
{ private String attrC = "testC"; }using the following test case:
TypeC c = new TypeC();
XStream xStream = new XStream(new DomDriver());
xStream.alias("test", TypeC.class);
xStream.aliasField("a", TypeA.class, "attrA");
xStream.aliasField("b", TypeB.class, "attrB");
xStream.aliasField("c", TypeC.class, "attrC");
String xml = xStream.toXML(c);
System.out.println(xml);
c = (TypeC) xStream.fromXML(xml);
The outoput was the following:
<test>
<c>testC</c>
<b>testB</b>
<a>testA</a>
</test>
The deserialization led to this exception:
com.thoughtworks.xstream.converters.ConversionException: b : b
---- Debugging information ----
message : b : b
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : b : b
class : com.test.TypeC
required-type : com.test.TypeC
path : /test/b
-------------------------------
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.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:29)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:832)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:819)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:767)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:759)
at com.test.TestHierarchy.test(TestHierarchy.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
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:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: b : b
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:72)
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.CGLIBMapper.realClass(CGLIBMapper.java:40)
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.reflection.AbstractReflectionConverter.determineType(AbstractReflectionConverter.java:269)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:165)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:121)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
... 28 more
I encountered that the FieldAliasingMapper keys attributes by their full qualified name, led by their parent class (what surprise). However, during deserialization the serialized 'test/b' leads to the attribute key 'com.test.TypeC.b' and not to 'com.test.TypeB.b'.
I remember an output where such a class structure led to some xml like this (w/o alias here):
<com.test.TypeC>
<com.test.TypeA>
<attrA>testA</attrA>
</com.test.TypeA>
<com.test.TypeB>
<attrB>testB</attrB>
</com.test.TypeB>
<attrC>testC</attrC>
</com.test.TypeC>
Unfortunately I do not remember which setting led to this output :T
Best regards,
Henrik
Thanks for reporting. It is fixed in subversion. Can you check?