removing class="list" from element

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

removing class="list" from element

philduhs
I have a class which contains a Collection that I want included in my XML however the XML element is automatically populated with an attribute: class="list" which I don't want.

This should be farily straightforward (and a common issue??) so apologies if I've overlooked something obvious but after spending a couple of hours looking in this forum and elsewhere I'm no closer to solving the problem. I can remove the element altogether (by using the @XStreamImplicitCollection annotation) and I already alias the element (by using the @XStreamAlias annotation) but I do want to see the element, just not it's class. I have also tried omitting the attribute by using xstream.omitField(... by setting the type to both "List" and "ArrayList" and the fieldName to "class" but this doesn't help either...

Help appreciated!

Rgds,
Phil
Reply | Threaded
Open this post in threaded view
|

RE: removing class="list" from element

Jörg Schaible
Hi Phil,

philduhs wrote on Tuesday, March 27, 2007 5:50 AM:

> I have a class which contains a Collection that I want
> included in my XML
> however the XML element is automatically populated with an attribute:
> class="list" which I don't want.
>
> This should be farily straightforward (and a common issue??)
> so apologies if
> I've overlooked something obvious but after spending a couple of hours
> looking in this forum and elsewhere I'm no closer to solving
> the problem. I
> can remove the element altogether (by using the
> @XStreamImplicitCollection
> annotation) and I already alias the element (by using the
> @XStreamAlias annotation) but I do want to see the element, just not
> it's
> class. I have
> also tried omitting the attribute by using
> xstream.omitField(... by setting
> the type to both "List" and "ArrayList" and the fieldName to "class"
> but this doesn't help either...
>
> Help appreciated!

XStream writes a class attribute if the member type does not match the type of the object instance stored in this field. Otherwise it is not necessary to deserialize the objects again. In your case the member seems of type collection, but you use actually an ArrayList? You may set the default implementation for Collection to be an ArrayList.

- Jörg

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

RE: removing class="list" from element

philduhs
Thanks, great explanation - I hadn't realised that's what caused XStream to write the class attribute. All fine now.

Phil


Jörg Schaible wrote
Hi Phil,

philduhs wrote on Tuesday, March 27, 2007 5:50 AM:

> I have a class which contains a Collection that I want
> included in my XML
> however the XML element is automatically populated with an attribute:
> class="list" which I don't want.
>
> This should be farily straightforward (and a common issue??)
> so apologies if
> I've overlooked something obvious but after spending a couple of hours
> looking in this forum and elsewhere I'm no closer to solving
> the problem. I
> can remove the element altogether (by using the
> @XStreamImplicitCollection
> annotation) and I already alias the element (by using the
> @XStreamAlias annotation) but I do want to see the element, just not
> it's
> class. I have
> also tried omitting the attribute by using
> xstream.omitField(... by setting
> the type to both "List" and "ArrayList" and the fieldName to "class"
> but this doesn't help either...
>
> Help appreciated!

XStream writes a class attribute if the member type does not match the type of the object instance stored in this field. Otherwise it is not necessary to deserialize the objects again. In your case the member seems of type collection, but you use actually an ArrayList? You may set the default implementation for Collection to be an ArrayList.

- Jörg

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

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

RE: removing class="list" from element

nitinagarwal81
This post has NOT been accepted by the mailing list yet.
In reply to this post by Jörg Schaible
Phil,

What you have done to fix that. I am getting same error.

I have declared my vairiable as

Collection<AddressDTO> addresses;
or Collection<AddressDTO> addresses = new ArrayList<AddressDTO>()

However both are not working.

Any help is appreciated.