Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] [MOXy] collection of elements with different names

Hi Polly,

If subclasses are involved (ShipToAddress, BillingAddress, and VendorAddress are all subclasses of Address and each maps to its corresponding element) then this can be mapped easily:
  • Use an XMLAnyCollectionMapping and set "ShipToAddress", "BillingAddress", and "VendorAddress" as the root elements.
  • Use an XMLChoiceCollectionMapping and map "ShipToAddress", "BillingAddress", and "VendorAddress" as the set of choice elements.
If subclasses are not involved then you are the second person to ask for this support.  I would be interested in your opinion on how to map it.

Unmarshalling is easy, you can do this today in the ways mentioned above.

The problem relates to marshalling, without some sort of descrminator EclipseLink MOXy doesn't know which element to marshal with.  Possibilities for descriniators include (position in list or a property on the object).

Alternatively  you can use an object to preserve the element info.  In JAXB you can preserve the element name in a JAXBElement, then you need List<JAXBElement<Address>> instead of List<Address>. 

Below is a link disucssion I've been having with someone else on this issue:
http://forums.oracle.com/forums/message.jspa?messageID=3976208#3976208

-Blaise

polly.c.chang wrote:
Hi,

Is it possible to map elements of different names to the same collection? 
As in something like mapping:

<Document>
    <ShipToAddress>...</ShipToAddress>
    <BillingAddress>...</BillingAddress>
    <VendorAddress>...</VendorAddress>
</Document>

To:

public class Document {
    private List<Address> addresses
}

Thanks!
--Polly
  

Back to the top