Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322284 - [OXM] Need a way to specify Collection Type in an xml-element
Summary: [OXM] Need a way to specify Collection Type in an xml-element
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 321152
  Show dependency tree
 
Reported: 2010-08-10 16:27 EDT by Rick Barkhouse CLA
Modified: 2022-06-09 10:29 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix. (24.27 KB, patch)
2010-09-29 12:51 EDT, David McCann CLA
no flags Details | Diff
Supporting test cases (38.93 KB, patch)
2010-09-29 12:51 EDT, David McCann CLA
no flags Details | Diff
Proposed fix. (24.18 KB, patch)
2010-09-29 14:07 EDT, David McCann CLA
no flags Details | Diff
Supporting test cases (38.93 KB, patch)
2010-09-29 14:07 EDT, David McCann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rick Barkhouse CLA 2010-08-10 16:27:30 EDT
For Dynamic JAXB we need a way of specifying the class of collection being used, so that the underlying dynamic JavaModel can be built correctly.  We currently have:

<xml-element java-attribute="zipCodes" type="java.lang.Integer" xml-list="true"/>

When xml-list is encountered, the JavaModel is asked if this property isArray(), but the only type information we have is Integer, and so an Integer property will be created (and therefore XMLProcessor will fail when processing this element).

If we could have a way of hooking up a ContainerPolicy then the information would be available to the Dynamic JAXB boostrapping code.

For example:

<xml-element java-attribute="zipCodes" type="java.lang.Integer" collection-type="java.util.ArrayList"/>

would allow us to generate

ArrayList<Integer> zipCodes

Other issues:
- Would also need a way to specify that the Java attribute is an array (e.g. 'Integer[] zipCodes')
- xml-list seems redundant if we were to add collection type information, should xml-list be assumed true in this case?
Comment 1 David McCann CLA 2010-09-24 09:25:02 EDT
The design Wiki for this issue can be found here: http://wiki.eclipse.org/EclipseLink/DesignDocs/322284
Comment 2 David McCann CLA 2010-09-24 09:37:47 EDT
xml-list should not be assumed in this case.  Consider this:  when a collection property is annotated with @XmlElement, each item in the collection will be wrapped by an element. For example,

 @XmlRootElement
 class Foo {
     @XmlElement
     List<String> data;
 }
 
would produce XML like this:

 <foo>
   <data>abc</data>
   <data>def</data>
 </foo>

@XmlList annotation, allows multiple values to be represented as whitespace-separated tokens in a single element. For example,

 @XmlRootElement
 class Foo {
     @XmlElement
     @XmlList
     List<String> data;
 }
 
would produce XML like this:

 <foo>
   <data>abc def</data>
 </foo>
Comment 3 David McCann CLA 2010-09-24 11:05:58 EDT
In JPA, an array type is declared using attribute-type as follows:

    attribute-type="java.lang.Integer[]"

I propose we do the same thing, i.e.

    collection-type="java.lang.Integer[]"
Comment 4 David McCann CLA 2010-09-29 12:51:23 EDT
Created attachment 179867 [details]
Proposed fix.
Comment 5 David McCann CLA 2010-09-29 12:51:36 EDT
Created attachment 179868 [details]
Supporting test cases
Comment 6 David McCann CLA 2010-09-29 14:07:42 EDT
Created attachment 179876 [details]
Proposed fix.
Comment 7 David McCann CLA 2010-09-29 14:07:55 EDT
Created attachment 179877 [details]
Supporting test cases
Comment 8 David McCann CLA 2010-09-29 14:08:42 EDT
Arrays will not be supported at this time.  An enhancement request has been opened to track this issue:  https://bugs.eclipse.org/bugs/show_bug.cgi?id=326548
Comment 9 David McCann CLA 2010-10-08 09:34:38 EDT
reviewed by:  matt.macivor@oracle.com
tests:  all unit tests pass as expected; jaxb/externalizedmetadata/xmlanyattribute/XmlAnyAttributeTestCases; jaxb/externalizedmetadata/xmlanyelement/XmlAnyElementTestCases; jaxb/externalizedmetadata/xmlattribute/XmlAttributeTestCases; jaxb/externalizedmetadata/xmlelement/XmlElementTestCases; jaxb/externalizedmetadata/xmlelement/XmlElementsTestCases; jaxb/externalizedmetadata/xmlelement/XmlValueTestCases
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:29:01 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink