Order of members in a class

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

Order of members in a class

Akshay Shrivastava
Is there a way to specify the order of elements in a class, without writing
a custom coverter?

So if I have an Address class, like this:

class Address {
private String addressLine1;
private String addressLine2;
private String city;
private String state;
private String zip;

...
}

XStream does not serialize them in the same order as they are declared in
the class.  Is there a way to specify the order or follow some convention
maybe!

Thanks,
Akshay

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/

Reply | Threaded
Open this post in threaded view
|

Re: Order of members in a class

Jörg Schaible-2


Hi Akshay,

Akshay Shrivastava wrote:

> Is there a way to specify the order of elements in a class, without
> writing a custom coverter?
>
> So if I have an Address class, like this:
>
> class Address {
> private String addressLine1;
> private String addressLine2;
> private String city;
> private String state;
> private String zip;
>
> ...
> }
>
> XStream does not serialize them in the same order as they are declared in
> the class.  Is there a way to specify the order or follow some convention
> maybe!

No. XStream uses an internal HashMap for the fields and you have currently no
possibility to configure it. You might derive your own ReflectionProvider
though and set an own implementation for the FieldDictionary. But remember,
that you start to use here internal XStream API and this might change in
future releases.

- Jörg

Reply | Threaded
Open this post in threaded view
|

Re: Re: Order of members in a class

Justin T. Sampson-2
On 1/7/06, Jörg Schaible <[hidden email]> wrote:

> > XStream does not serialize them in the same order as they are
> > declared in the class. Is there a way to specify the order or
> > follow some convention maybe!
>
> No. XStream uses an internal HashMap for the fields and you have
> currently no possibility to configure it. You might derive your
> own ReflectionProvider though and set an own implementation for
> the FieldDictionary. But remember, that you start to use here
> internal XStream API and this might change in future releases.

Really? I haven't tried it in a while, but I seem to remember that
originally fields were output in alphabetical order but that later
the code was changed to output them in declaration order. Is my
memory failing?

Cheers,
Justin
Reply | Threaded
Open this post in threaded view
|

Re: Re: Order of members in a class

Jörg Schaible-2
Justin T. Sampson wrote:

> On 1/7/06, Jörg Schaible <[hidden email]> wrote:
>
>> > XStream does not serialize them in the same order as they are
>> > declared in the class. Is there a way to specify the order or
>> > follow some convention maybe!
>>
>> No. XStream uses an internal HashMap for the fields and you have
>> currently no possibility to configure it. You might derive your
>> own ReflectionProvider though and set an own implementation for
>> the FieldDictionary. But remember, that you start to use here
>> internal XStream API and this might change in future releases.
>
> Really? I haven't tried it in a while, but I seem to remember that
> originally fields were output in alphabetical order but that later
> the code was changed to output them in declaration order. Is my
> memory failing?

Well, this was, what I concluded from a short code review, but Joe or Mauro
may correct me ...

- Jörg