Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » XmlAdapter with xml-path(Moxy XmlAdapter)
XmlAdapter with xml-path [message #1288789] Tue, 08 April 2014 21:40
Mar Sah is currently offline Mar SahFriend
Messages: 2
Registered: April 2014
Junior Member
I am stuck with trying to use an XmlAdapter in my xml-bindings document to unmarshal xml. The xml looks like this and can't be modified:


The classes to be mapped as follows:

public class PO {
String id;
Address vendorAddress;
Address buyerAddress;

public class Address {
String city;
String state;

Now since multiple tags map to the Address class, I have the following XmlAdapter to handle the buyer Address:

public class BuyerAddressAdapter extends XmlAdapter<BuyerAddressAdapter.BuyerAddress, Address> {

public static class BuyerAddress {
public String BuyerCity;
public String BuyerState;

public BuyerAddress marshal(Address v) {
BuyerAddress a = new BuyerAddress();
a.BuyerCity =;
a.BuyerState = v.state;
return a;

public Address unmarshal(BuyerAddress v) {
Address a = new Address(); = v.BuyerCity;
a.state = v.BuyerState;
return a;

Here is the bindings file:

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns=""
package-name="ipp.valueobject" xml-mapping-metadata-complete="true" >

<java-type name="Orders" xml-accessor-type="NONE">
<xml-root-element name="Orders" />
<xml-elements java-attribute="orders">
<xml-element name="PO" type="ipp.valueobject.PO" />

<java-type name="PO" xml-accessor-type="NONE">
<xml-element java-attribute="id" xml-path="POHeader/ID/text()" />
<xml-element java-attribute="vendorAddress" xml-path="."
type="Address" />

<xml-element java-attribute="buyerAddress" xml-path="." >
<xml-java-type-adapter value="BuyerAddressAdapter" />


When I run the test, the id and vendorAddress fields have the correct values, but the fields in the buyerAddress object are null. I tried changing the xml-path of buyerAddress to be xml-path="POHeader". When I do this, the buyerAddress has the correct values but then the id and vendorAddress fields are null. It is like changing the xml-path causes the other elements to be consumed.

I don't understand what I am doing wrong. Any help is appreciated.

Previous Topic:Insert Duplicate key Exception - Eclipselink
Next Topic:don't get latest data from database
Goto Forum:

Current Time: Tue Mar 31 00:14:20 GMT 2020

Powered by FUDForum. Page generated in 0.02866 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top