users@jaxb.java.net

Re: Order of marshalling items in a collection in JAXB 2.1

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 4 Dec 2009 09:32:54 +0100

It seems that you have discovered an omission in the spec. Although,
from the Java point of view, not all iterable collections have a specific
order, in the sense that the same Java program will, or is bound to,
produce the same order on different JVMs.

A quote from the spec:
"If the ordering between the children elements is significant and must be
accessible to the Java application, then the ordering is naturally
preserved in Java representation via a collection."

I interpret this to hold for both directions, i.e., whenever the Java
collection type implies a portable order of its elements then this
will be the order of the marshalled XML elements.

-W

On Thu, Dec 3, 2009 at 7:21 PM, Nigel Kerr <nigel.kerr_at_gmail.com> wrote:

> Hello,
>
> There is a idea that JAXB does not provide ordering guarantees of
> child elements. I've had colleagues assert this, and I see it in
> discussions like
> http://forums.sun.com/thread.jspa?forumID=34&threadID=622325 . I
> haven't found an example that actually demonstrates that ordering at
> either marshalling or unmarshalling is unreliable.
>
> I would like to be able to refer to the JAXB 2 Spec on what, if
> anything, is promised about the ordering of elements.
>
> From reading exactly The JavaTM Architecture for XML Binding (JAXB)
> 2.1 Final Release December 11, 2006, I believe:
>
> 1. @XmlType's propOrder property can be used to specify the order of
> properties: if my schema defines a sequence of three different
> elements, I expect xjc to list three corresonding properties in the
> same order in the corresponding @XmlType annotation.
>
> 2. Appendix B "Runtime Processing", section 3 "Unmarshalling",
> sub-section 3.4 "Element Information Item", directs that an element
> information item whose .property is a collection type, shall be added
> to the end of the collection. This promises that, at least when the
> XML instance is schema-valid, document order and the order of items in
> the collection will be the same.
>
> I am unable to identify statements similar to #2 for Marshalling. B.4
> "Marshalling" does not speak about collection types, or at least not
> that I understand. What I am looking for is a statement such as:
>
> The order of objects in the collection is the order in which they
> will be marshalled.
>
> Does such a statement, or anything related to it, exist? Is this so
> obvious I've missed it?
>
> cheers,
> Nigel Kerr
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>