Details
-
Type: New Feature
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.2
-
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.
I also need such a feature. Preferably I would like to be able to register aliases for an element to specify that the instance vars should be attributes, not child elements.
I have looked at writing a new StringConverter, but it seems more complicated than that as there is something else that builds the xml String. If someone gives me a pointer I'll contribute the actual work.