I m working with eBay s LMS (Large Merchant Services) and kept running into the error:
org.xml.sax.SAXException:
SimpleDeserializer encountered a child
element, which is NOT expected, in
something it was trying to
deserialize.
After a lot of trial and error I traced the problem down. It turns out this works:
<?xml version="1.0" encoding="UTF-8"?>
<BulkDataExchangeRequests xmlns="urn:ebay:apis:eBLBaseComponents">
<Header>
<Version>583</Version>
<SiteID>0</SiteID>
</Header>
<AddFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
While this (what I ve been sending) doesn t:
<?xml version="1.0" encoding="UTF-8"?>
<BulkDataExchangeRequests xmlns="urn:ebay:apis:eBLBaseComponents">
<Header>
<Version>583</Version>
<SiteID>0</SiteID>
</Header>
<AddFixedPriceItemRequest>
The difference is the XML namespace attribute on the AddFixedPriceItemRequest
. All of my XML is currently being marshalled via JAXB and I m not sure what is the best way to go about adding a second xmlns attribute to a different element in my file.
So that s the question. How do I add an xmlns attribute to another element in JAXB?
package ebay.apis.eblbasecomponents;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AddFixedPriceItemRequestType", propOrder = {
"item"
})
public class AddFixedPriceItemRequestType
extends AbstractRequestType
{
@XmlElement(name = "Item")
protected ItemType item;
public ItemType getItem() {
return item;
}
public void setItem(ItemType value) {
this.item = value;
}
}
Added class definition by request.
Edited the above class like so to no effect:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "urn:ebay:apis:eBLBaseComponents",
name = "AddFixedPriceItemRequestType", propOrder = {
"item"
})
public class AddFixedPriceItemRequestType
Here is a snippet of the BulkDataExchangeRequestsType
class. I tried throwing a namespace="urn:ebay:apis:eBLBaseComponents"
into the @XmlElement
for AddFixedPriceItemRequest
but it didn t do anything.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BulkDataExchangeRequestsType", propOrder = {
"header",
"addFixedPriceItemRequest"
})
public class BulkDataExchangeRequestsType {
@XmlElement(name = "Header")
protected MerchantDataRequestHeaderType header;
@XmlElement(name = "AddFixedPriceItemRequest")
protected List<AddFixedPriceItemRequestType> addFixedPriceItemRequest;