Is there a way to map two references in JAXB XML entities for different classes?

Is there a way to map two references in JAXB XML entities for different classes? Example:

<restresource>
  <atom:link rel="http://myuri/rels/author" href="http://myuri/users/42" title="That me"/>
  <atom:link rel="http://myuri/rels/customer" href="http://myuri/customers/4711" title="John Smith"/>
</restresource>

I would like to map the first link with the XMLAdapter to the User class, and the second to another XMLAdapter for the Customer class. I tried to do this using @XmlPath from EclipseLink JAXB (MOXy) . But the result was not obtained from a large number of experiments, since it is impossible to determine the path with the conditions for "rel". I understand that this can only be done in conjunction with an adapter, because otherwise the definition will not be bidirectional. Any idea how to implement this?

+3
source share
1 answer

MOXy @XmlPath, . EclipseLink 2.3 :

@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;

, EclipseLink 2.3.0 ( 22 ) :

, EclipseLink JAXB (MOXy).

+1

All Articles