Details
Description
The following email exchange explains everything:
Hi Tom,
________________________________
From: Thomas P. Fuller
Sent: Wednesday, February 27, 2008 12:50 PM
Subject: Re: [xstream-user] Re: Question about changing the default root name when xstream.toXML / fromXML is invoked
Hi Jorg,
I've actually tried this and I've done it again, just to make sure I've not missed something.
Here's the simple test, and output:
Code:
public void test1 () {
XStream xstream = new XStream (new JettisonMappedXmlDriver ());
xstream.setMode(XStream.NO_REFERENCES);
xstream.alias("CriterionValueTypeArgument", CriterionValueTypeArgument.class);
xstream.alias("CriterionValueTypeArguments", CriterionValueTypeArgument[].class);
CriterionValueTypeArgument cvta = new CriterionValueTypeArgument ();
cvta.setValue("value");
cvta.setDataValue("dataValue");
cvta.setDataType("dataType");
cvta.setDisplayValue("displayValue");
CriterionValueTypeArgument[] list = new CriterionValueTypeArgument[]
{ cvta };
String result = xstream.toXML (list);
System.out.println("test1; json text: " + result);
}
Output:
test1; json text: {"CriterionValueTypeArgument-array":{"CriterionValueTypeArgument":
{"value":"value","dataValue":"dataValue","dataType":"dataType","displayValue":"displayValue"}}}
Tom
________________________________
Unfortunately you're right. I could have sweared, that aliasing array types work and I already used it. Can you open a JIRA issue for this as enhancement request?
- Jörg
---------------------------------------------------------------------
A work-around provided by Jörg is as follows:
Yeah, since it is as I already stated: It is currently not supported. At serialization time XStream will add its array marker to the tag name to be able to deserialize it. This marker is added before any alias handling. The deserialization works though, since the array marker is missing and XStream will find then the alias.
You can implement a small workaround though using a custom mapper:
XStream xstream = new XStream() {
MapperWrapper wrapMapper(MapperWrapper next) {
return new MapperWrapper(next) {
public String serializedClass(Class type)
}
}
};
This is implemented now in the head revision.