Is there any way to map two links in a JAXB XML entity to different classes?
Is there any way to map two links in a JAXB XML entity to different classes? Example:
<restresource>
<atom:link rel="http://myuri/rels/author" href="http://myuri/users/42" title="That's me"/>
<atom:link rel="http://myuri/rels/customer" hre开发者_运维技巧f="http://myuri/customers/4711" title="John Smith"/>
</restresource>
I'd like to map the first link with a XMLAdapter to the class User and the second one with a different XMLAdapter to class Customer. I tried to do that with @XmlPath from EclipseLink JAXB (MOXy). But didn't got any result from a lot of experiments since it's not possible to define a path with conditions on "rel". I understand that this could only be done in combination with the Adaptor because otherwise the definition would not be bidirectional. Any idea how to realize that?
We've added an extension to MOXy's @XmlPath that will make this use case easier to map. In EclipseLink 2.3 you will be able to do the following:
@XmlPath("atom:link[@rel='http://myuri/rels/author'])
@XmlJavaTypeAdapter(AuthorAdapter.class)
private Author author;
@XmlPath("atom:link[@rel='http://myuri/rels/customer'])
@XmlJavaTypeAdapter(CustomerAdapter.class)
private Customer customer;
You can try this feature out today by downloading one of the EclipseLink 2.3.0 nightly downloads (starting March 22) from:
- http://www.eclipse.org/eclipselink/downloads/nightly.php
For more information
- http://bdoughan.blogspot.com/2011/03/map-to-element-based-on-attribute-value.html
I will also try to put together an approach that is compatible with released versions of EclipseLink JAXB (MOXy).
精彩评论