History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-67
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Brian Slesinsky
Votes: 4
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
XStream

Provide a way to control the order in which fields are listed

Created: 12/May/04 10:29 PM   Updated: 24/May/07 12:38 AM
Component/s: Core
Affects Version/s: 1.1
Fix Version/s: 1.2.2

File Attachments: 1. Text File xstr-67.patch (13 kb)

Issue Links:
Related
 
Supercedes
 


 Description  « Hide
Fields are currently always listed in alphabetical order. In my quest to make our objects pretty-print nicer, I'd like to change the order. This can be done with converters, but it could be made more convenient.

One possible API:

xstream.setFieldOrder(Address.class,
new String[] {"name", "address1", "address2", "city", "state", "zip"})

I'd expect that any unmentioned fields should be tacked onto the end, and specifying a field name that's not in the class should be an error.



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
gui - 19/May/04 05:45 AM
Keeping the fields order as it is in the class would already be better than alfabetic. Don't know whether that's possible with reflection though..

Joerg Schaible - 22/Mar/06 03:51 PM
The field order is the declaration order now.

Thomas Stets - 25/Jul/06 08:09 AM
We have similar problems as described in XSTR-259. I think being able to specify the order of the fields in the XML will solve our problem.

Thomas Stets - 13/Nov/06 11:15 AM
This patch implements the requested functionality.

Changes to the API:

com.thoughtworks.xstream.XStream has a new method setFieldSortOrder(Class clazz, List sortedFields).
This method takes a Class and a List of field names. When an object of that class is serialized, first the
fields named in that list are written out, in the order of the list. After that all remaining fields are written
in the same order they would have come out before.

The functionality is more or less the one being requested, except that XStream will not throw an Exception
when an unknown field name is given in the list. (There are several reasons for and against throwing an
Exception in this case. I decided not to throw one, but would be equally happy with the other way)


Guilherme Silveira - 10/Apr/07 09:38 AM
We have provided a similar solution. Please take a look on the source from svn and close the issue if this is fine.