Text content and attributes output incorrect (1.4.4)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Text content and attributes output incorrect (1.4.4)

Jörg Schaible-2
Hi Tamas,

Farago, Tamas wrote:

> 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 :)

Can you open a JIRA issue, please? Your xircles account for this ML is the
same for JIRA. Enums are handled specially in XStream and it seems there's
something lost in this 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.
 
We used an (existing) annotation at class level, because when you annotate
the field, you make also decisions for derived classes which might be out
of
your control. Especially it is possible that this converter cannot handle a
derived class at all because of new complex members. Or you might derive
from a class out of your control that contains the field that should be
used
as tag value.
 
> 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.

In the last 10 years we found two types of JDKs: The ones that serialize in
declaration order and the ones that reverse the order (older ones from
IBM).
However, it is not the JVM, but the compiler that defines the order, so it
depends on the JDK that was used to create the class files.

So, you are technically right, but at least I do currently not know any
compiler that does it not in declaration sequence.

However, if you sort the elements yourself, you may run into trouble if you
do not write and read the fields of a parent class first.

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: Text content and attributes output incorrect (1.4.4)

Farago, Tamas
Hi Jörg,

Thanks, for the quick reply.

> Can you open a JIRA issue, please? Your xircles account for this ML is the
> same for JIRA. Enums are handled specially in XStream and it seems there's
> something lost in this converter.

I have created XSTR-741 on JIRA. Had some troubles first as I only signed up for the "manage email" feature of codehaus that didn't include any of the JIRA login.

> So, you are technically right, but at least I do currently not know any
>compiler that does it not in declaration sequence.
>
>However, if you sort the elements yourself, you may run into trouble if you
>do not write and read the fields of a parent class first.

You are right in this. It is good though to keep something like this in mind, especially if you are developing on one machine, and actual releases get built on a different server with who knows what java environment.

Regards,
Tamas

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


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: Text content and attributes output incorrect (1.4.4)

Jörg Schaible-3
Hi Tamas,

Farago, Tamas wrote:

> Hi Jörg,
>
> Thanks, for the quick reply.

quick is different, Gmane kept my emails for the last 2 days :-(

>> Can you open a JIRA issue, please? Your xircles account for this ML is
>> the same for JIRA. Enums are handled specially in XStream and it seems
>> there's something lost in this converter.
>
> I have created XSTR-741 on JIRA. Had some troubles first as I only signed
> up for the "manage email" feature of codehaus that didn't include any of
> the JIRA login.

Oh, thanks for this info. I was not aware of it. I always thought, any
xircles account would suffice. What had you to do to turn your account into
a full one?
 
>> So, you are technically right, but at least I do currently not know any
>>compiler that does it not in declaration sequence.
>>
>>However, if you sort the elements yourself, you may run into trouble if
>>you do not write and read the fields of a parent class first.
>
> You are right in this. It is good though to keep something like this in
> mind, especially if you are developing on one machine, and actual releases
> get built on a different server with who knows what java environment.

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email