Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of marshalling items in a collection in JAXB 2.1 #250

Open
Tomas-Kraus opened this issue Dec 4, 2009 · 4 comments
Open

Order of marshalling items in a collection in JAXB 2.1 #250

Tomas-Kraus opened this issue Dec 4, 2009 · 4 comments
Assignees
Labels
enhancement New feature or request Major Priority

Comments

@Tomas-Kraus
Copy link
Contributor

Per request of Martin Grebac, I am filing the question from the jaxb-users list (at the URL, but also
reproduced here) as a specification question. Please advise if more or different information is needed.
Thank you.


from Wolfgang Laun wolfgang.laun@gmail.com
reply-to users@jaxb.dev.java.net
to users@jaxb.dev.java.net
date Fri, Dec 4, 2009 at 3:32 AM
subject Re: Order of marshalling items in a collection in JAXB 2.1

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

  • Hide quoted text -
    On Thu, Dec 3, 2009 at 7:21 PM, Nigel Kerr nigel.kerr@gmail.com wrote:
  • Hide quoted text -
    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 eclipse-ee4j/jaxb-ri#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

from Nigel Kerr nigel.kerr@gmail.com
to users@jaxb.dev.java.net
date Fri, Dec 4, 2009 at 7:01 AM
subject Re: Order of marshalling items in a collection in JAXB 2.1
mailed-by gmail.com

This may be as strong a reed as there is in the current spec, then. I
would advocate strengthening this aspect, possibly:

All collection types are list or array types expressly, not just bags
or sets, unless otherwise specified

or even just something on what exactly happens to the collections at
marshalling time, regardless of what the type is ("All arrays are
consulted from index zero sequentially, all Collection types are
iterated by their default iterators").

Thank much.

Environment

Operating System: All
Platform: All
URL: http://old.nabble.com/Order-of-marshalling-items-in-a-collection-in-JAXB-2.1-td26630658.html

Affected Versions

[2.1]

@Tomas-Kraus
Copy link
Contributor Author

@glassfishrobot Commented
Reported by nigel_kerr0

@Tomas-Kraus
Copy link
Contributor Author

@glassfishrobot Commented
Was assigned to snajper

@Tomas-Kraus
Copy link
Contributor Author

@glassfishrobot Commented
This issue was imported from java.net JIRA JAXB-724

@Tomas-Kraus
Copy link
Contributor Author

@lukasj lukasj transferred this issue from eclipse-ee4j/jaxb-ri May 19, 2022
@lukasj lukasj added enhancement New feature or request and removed Component: spec labels May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Major Priority
Projects
None yet
Development

No branches or pull requests

3 participants