History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-480
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Joerg Schaible
Reporter: Thomas P. Fuller
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XStream

XStream does not properly alias arrays of objects.

Created: 28/Feb/08 04:11 PM   Updated: 29/Sep/08 02:28 PM
Component/s: Core
Affects Version/s: 1.2.2
Fix Version/s: 1.x Maintenance


 Description  « Hide
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) { return type == CriterionValueTypeArgument[].class ? "CriterionValueTypeArguments" : super.serializedClass(type); }
}
}
};



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Joerg Schaible - 29/Sep/08 02:28 PM
This is implemented now in the head revision.