Saving order in list of elements.

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

Saving order in list of elements.

xxx xxx
Hello!

I have following:
xml:
<library>
   <book author = "A"/>
   <book author = "B"/>
   <book author = "C"/>
</library>

and it's classes:

@XStreamAlias("library")
public class bigLibrary
{  
        private List<book> books;
        ...
}

@XStreamAlias("book")
public class singleBook
{  
    @XStreamAsAttribute
        private String author;
        ...
}

Question:
How can i save order in list of elements while serialization and while deserialization?
In this example after deserialization list "books" should be: books[0] - A, books[1] - B, books[2] - C, and after serialization
xml should have order of nodes called "book" as it's in list "books".

Thanks in advance.



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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Saving order in list of elements.

Jörg Schaible-2
Hi,

xxx xxx wrote:

> Hello!
>
> I have following:
> xml:
> <library>
>    <book author = "A"/>
>    <book author = "B"/>
>    <book author = "C"/>
> </library>
>
> and it's classes:
>
> @XStreamAlias("library")
> public class bigLibrary
> {  
> private List<book> books;
> ...
> }
>
> @XStreamAlias("book")
> public class singleBook
> {  
>     @XStreamAsAttribute
> private String author;
> ...
> }
>
> Question:
> How can i save order in list of elements while serialization and while
> deserialization? In this example after deserialization list "books" should
> be: books[0] - A, books[1] - B, books[2] - C, and after serialization xml
> should have order of nodes called "book" as it's in list "books".

A sequence in XML matters as it is for Java with a List. So where is the
problem? However, you should start to serialize from Java to XML and tweak
the output until it matches the XML you want to read. It is really tedious
to do it the other way round. Also look at the various tutorials, you will
need an implicit collection here.

- Jörg


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

    http://xircles.codehaus.org/manage_email