Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323756 - JAXB Externalized Metadata: xml-idref not working with xml-elements
Summary: JAXB Externalized Metadata: xml-idref not working with xml-elements
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Matt MacIvor CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 317962 323986
  Show dependency tree
 
Reported: 2010-08-26 16:30 EDT by David McCann CLA
Modified: 2022-06-09 10:09 EDT (History)
0 users

See Also:


Attachments
proposed fix and test case (131.27 KB, patch)
2010-11-02 10:53 EDT, Matt MacIvor CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David McCann CLA 2010-08-26 16:30:26 EDT
Given the following object model:

public class Root {
    public Bar bar;
    public List<Address> addresses;
    public List<Phone> phoneNumbers;
}
public class Bar {
    public List items;
}
public class Address {
    public String id;
    public String street;
    public String location; 
}
public class Phone {
    public String id;
    public String number;
    public String location;    
}

And the following eclipselink-oxm.xml file:

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm">
  <java-types>
    <java-type name="org.example.Root">
      <java-attributes>
        <xml-element java-attribute="bar" />
        <xml-element java-attribute="addresses" xml-path="address" />
        <xml-element java-attribute="phoneNumbers" xml-path="phone" />
      </java-attributes>
    </java-type>
    <java-type name="org.example.Bar">
      <java-attributes>
        <xml-elements java-attribute="items" xml-idref="true">
          <xml-element java-attribute="address" xml-path="address/@id" 
              type="org.example.Address"/>
          <xml-element java-attribute="phone" xml-path="phone/@id" 
              type="org.example.Phone" />
          <xml-element-wrapper name="contact" />
        </xml-elements>
      </java-attributes>
    </java-type>
    <java-type name="org.example.Address">
      <java-attributes>
        <xml-element java-attribute="id" xml-id="true" />
      </java-attributes>
    </java-type>
    <java-type name="org.example.Phone">
      <java-attributes>
        <xml-element java-attribute="id" xml-id="true" />
      </java-attributes>
    </java-type>
  </java-types>
</xml-bindings>

When unmarshalling the following instance document:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <bar>
        <contact>
            <phone id="2" />
            <address id="3" />
            <phone id="1" />
        </contact>
    </bar>
    <address>
        <id>1</id>
        <street>Anystreet Rd.</street>
        <location>Kanata</location>
    </address>
    <address>
        <id>2</id>
        <street>Somestreet Ave.</street>
        <location>Montreal</location>
    </address>
    <address>
        <id>3</id>
        <street>Nowhere Street</street>
        <location>Almonte</location>
    </address>
    <phone>
        <id>1</id>
        <number>617.288.4636</number>
        <location>Ottawa</location>
    </phone>
    <phone>
        <id>2</id>
        <number>617.858.4636</number>
        <location>West Carleton</location>
    </phone>
    <phone>
        <id>3</id>
        <number>617.555.4636</number>
        <location>Unknown</location>
    </phone>
</root>

We would expect to get a Root object with 1 Bar, 3 Addresses and 3 Phones.  Most important we'd expect that the Bar object would contain 3 entries in its 'items' list:

- Phone (id=2, number=617.858.4636, location=West Carleton)
- Address (id=3, street=Nowhere Street, location=Almonte)
- Phone (id=1, number=617.288.4636, location=Ottawa)

This is not the case, however.  The Bar object has 2 Phone and 1 Address entries, but non of their property values are populated (they are all null).

In MappingsGenerator we don't check for XmlIDREF when constructing our Choice mapping, but should.  Currently Choice mappings only support direct/composite and directcollection/compositecollection.  We will need to include object/collection reference mappings as well.
Comment 1 Matt MacIvor CLA 2010-11-02 10:53:56 EDT
Created attachment 182211 [details]
proposed fix and test case
Comment 2 Matt MacIvor CLA 2010-11-02 11:37:21 EDT
Proposed fix checked into SVN
Reviewed by Blaise Doughan and David McCann
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:03:47 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:09:50 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink