Details
-
Type: New Feature
-
Status: Closed
-
Priority: Major
-
Resolution: Won't Fix
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
Currently, the xml XStream is created is quite straight forward and sometimes it is producing unnecessary tags for the object properties. For example:
class Student
{
String name="blah";
String lastname = "bloh";
}
public class School
{
String name = "My school";
int numberOfStudents = 1234;
List students;
}
AFAIK, current XSteam is producing this XML for such classes (lets assume we make necessary aliases)
<school>
<name>My School</name>
<numberOfStudents>1234</numberOfStudents>
<students>
<student>
<name>blah</name>
<surname>bloh</name>
</student>
....
</students>
</school>
But if you make primitive and String (and perhaps StringBuffer) properties of a class as attributes of an xml element, resulting xml qould be much shorter. like:
<school name="My School" numberOfStudents="1234">
<students>
<student name="blah" surname="bloh" />
....
</students>
</school>
i gues it does not disturb the background work of the XStream becuase there still is no configuration file whatsoever. only a set value like "MAKE_PRIMITIVES_ATTRIBUTES" would be enough for the user.
As already said in
XSTR-62, you can use the useAttributeFor method to declare arbitrary types to be written as attributes. If you like to use attributes for all primitives you can easily write a little helper function that does this and register them all. I see no need for a converter here at all.