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 Blaise,

Yes, in this use case, we don't want to create subclasses for all those
different kinds of "address" elements.  They would just add noise since
they're all the same.  You are saying that I can still unmarshal them using
XMLAnyCollectionMapping or XMLChoiceCollectionMapping right?  That's great. 
I did not think about those for some reason.

As for how to determine which element name is used during marshalling:

1.  Using the positioning would not work for us since we cannot be guarantee
that.
2.  I would not want to affect the object model with references to
JAXBElement like "List<JAXBElement<Address>>".  
3.  I would like something simpler than the converter approach.  
4.  I like having a property in the object that serves as the discriminator
to determine which element name to use.

Option #4 would be easiest and most natural for our use case.

Thanks!
--Polly


Blaise Doughan wrote:
> 
> 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
>>   
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 

-- 
View this message in context: http://old.nabble.com/-MOXy--collection-of-elements-with-different-names-tp26822805p26834716.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top