Details
-
Type: New Feature
-
Status: Closed
-
Resolution: Won't Fix
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
JDK version and platform:any
Description
Provide the ability to optionally change Xstream's XML output such that it contains the fqcn name and object name as attributes in each node of the XML as in the following example.
<object fqcn="com.somecompany.SomeClass" name="someClass1">
<object fqcn="java.lang.String" name="str1">This is a test</object>
<object fqcn="com.somecompany.SomeOtherClass" name="someClass2">
<object fqcn="java.lang.Integer" name="integer1">100</object>
<object fqcn="java.lang.String" name="str2">This is a test</object>
</object>
</object>
Hi,
looking at the example I suspect rather some strange use case than a real scenario that is often used. What is exactly the "name"? If you mean the field name, what should XStream do if there's no field e.g. any element in a collection?
However, you can accomplish both with workarounds. For the fqcn you may overload the convert method of the TreeMarshaller:
For the name you may overwrite the startNode method of the HierarchicalStreamWriter in use and instead of writing the tag name, you may write object and add immediately the name attribute with the real tag name.