Details
-
Type: Improvement
-
Status: Closed
-
Priority: Minor
-
Resolution: Fixed
-
Affects Version/s: 1.3.1
-
Fix Version/s: 1.4.5
-
Component/s: Converters
-
Labels:None
-
JDK version and platform:Sun 1.5.0_18 for Windows
Description
JavaClassConverter does not use the class aliasing mapper. It writes and reads non-aliased class names. Example:
public class C1 implements Serializable {
private static final long serialVersionUID = 1L;
}
public class C2 implements Serializable {
static private final long serialVersionUID = 1L;
public HashMap<Class<?>, Integer> f = new HashMap<Class<?>, Integer>();
public C2()
{ f.put(C1.class, Integer.valueOf(1)); }}
public class Test {
public static void main(String[] args) throws IOException
public static void serialize(XStream xstream, File file) throws IOException {
C2 c2 = new C2();
OutputStream os = new FileOutputStream(file);
try
{ xstream.toXML(c2, os); }finally
{ os.close(); } }
}
writes
<a2>
<f>
<entry>
<java-class>javaClass.C1</java-class>
<int>1</int>
</entry>
</f>
</a2>
and not
<a2>
<f>
<entry>
<java-class>javaClass.a1</java-class>
<int>1</int>
</entry>
</f>
</a2>
Actually this also applies to the JavaMethodConverter and JavaFieldConverter. However, it is not possible to activate this in general, because the mapping between a serialized type name and a class name is also influenced by the settings to default implementation, type aliases and XStream does here not separate between primitive types and their object counterpart (it uses the same aliases for both).
With aliasing support for these converters you would get following effect:
I bet, this is not what you wanted.