Hi,

 

I am evaluating using XStream for our project and have run into the
issue of adding text-content to XM using latest version of XStream,
1.4.4. It doesn't matter if I use the built-in XPP or the StaxDriver,
they both have the same result.

I have the following simple snippet I want to convert:

 

Enum Symbology {RIC, ISIN}

 

@XStreamAlias("Underlying")

@XStreamConverter(value = ToAttributedValueConverter.class, strings =
{"Underlying"})

public class UnderlyingView {

    @XStreamAsAttribute public Symbology symbology;

    public String Underlying;

}

 

Whenever I convert this to XML I get the following data. Obviously this
is a very simple snippet of code (groovy actually), but this reproduces
it for me:

XStream xStream = new XStream()

UnderlyingView un = new UnderlyingView([symbology: "RIC", Underling:
"underlying1"])

String result = xStream.toXML(un)

 

Output::

<?xml version="1.0" ?><Underlying>RICunderlying1</Underlying>

 

The text content is all fine, however the attribute, which is an enum is
lost, and merged into the text node.

Why is this? I do want to note that if I create a custom converter for
UnderlyingView where I marshal/unmarshal this class myself it works of
course. But I'd rather go without the custom converter :)

Additionally, would it be possible to change the API for text content?
It looks overly complicated, an annotation like @XStreamAsText in front
of the text value would be a lot easier; e.g. like SimpleXML, they just
annotate with @Text and it works. That framework has other problems so
for us XStream would be a better match.

 

I would also like to point out that on the FAQ the statement about
"fields are serialized in the order of declaration" is incorrect. The
JVM does not give you any guarantee about the order it returns you the
fields during reflection, so if you want to ensure a particular order
you have to code it yourself.

 

Thanks.

 

 


=============================================================================== 
Please access the attached hyperlink for an important electronic communications 
disclaimer: 
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
=============================================================================== 

Reply via email to