Reputation: 3412
I hava the following structure:
<data name="piece-shipment" error-status="0"
product-name="test" name="Hook" street="Freeway 21" city="Bumphill"/>
and the following jaxb annotated model..
@XmlRootElement(name = "data")
@XmlAccessorType(XmlAccessType.FIELD)
public class PieceShipment {
/**
* The field describes, of the parcel is returned to the origin sender
*/
@XmlAttribute(name = "product-name")
private String productName;
/**
* recipient information
*/
@XmlJavaTypeAdapter(RecipientAdapter.class)
private Recipient recipient;
.....
}
@XmlAccessorType(XmlAccessType.FIELD)
public class Recipient {
private String name;
private String street;
private String city;
...
}
How can I map the relation of PieceShipment to Recipient? They are on the same element level.
I've tried to use Adapters, but the adapter doesn't get called.
Upvotes: 1
Views: 212
Reputation: 149037
Using the standard JAXB (JSR-222) mapping metadata you can't have the properties from Recipient
mapped into the same parent element that PieceShipment
is mapped to.
If you are using EclipseLink MOXy as your JAXB provider then you can use our @XmlPath
extension to accomplish this:
@XmlPath(".")
private Recipient recipient;
For More Information
I have written more about MOXy's XPath mapping extension on my blog:
Upvotes: 1