I am trying to map the below XML to POJOs using JAXB so that I can use the data in the XML, however, I'm getting the error below:
! javax.xml.bind.UnmarshalException: unexpected element
(uri:"http://webservices.amazon.com/AWSECommerceService/2011-08-01",
local:"ItemSearchResponse"). Expected elements are <{}ItemSearchResponse>
XML:
<ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
<Items>
<Item>
<ASIN>B001DJLCRC</ASIN>
<DetailPageURL>
http://www.amazon.com/Breaking-Bad-Complete-First-Season/dp/B001DJLCRC%3FSubscriptionId%3DAKIAJ6JZ43XIWIUIIQLA%26tag%3Dsample026-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB001DJLCRC
</DetailPageURL>
<ItemLinks>
<ItemLink>
<Description>Technical Details</Description>
<URL>
http://www.amazon.com/Breaking-Bad-Complete-First-Season/dp/tech-data/B001DJLCRC%3FSubscriptionId%3DAKIAJ6JZ43XIWIUIIQLA%26tag%3Dsample026-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB001DJLCRC
</URL>
</ItemLink>
</ItemLinks>
<ItemAttributes>
<Actor>Bryan Cranston</Actor>
<Actor>Aaron Paul</Actor>
<Manufacturer>Sony Pictures Home Entertainment</Manufacturer>
<ProductGroup>DVD</ProductGroup>
<Title>Breaking Bad: The Complete First Season</Title>
</ItemAttributes>
</Item>
</Items>
</ItemSearchResponse>
My POJOs (getter/setters are skipped from question on purpose)
ItemSearchResponse
@XmlRootElement(name="ItemSearchResponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class ItemSearchResponse
{
@XmlElement(name="Items")
private Items items = null;
}
Items
@XmlAccessorType(XmlAccessType.FIELD)
public class Items {
@XmlElement(name="Item")
List<Item> items = new ArrayList();
}
Item
@XmlAccessorType(XmlAccessType.FIELD)
public class Item {
@XmlElement(name="ASIN")
private String asin;
@XmlElement(name="ItemAttributes")
private ItemAttributes attributes;
}
Item Attributes
@XmlAccessorType(XmlAccessType.FIELD)
public class ItemAttributes {
@XmlElement(name="Title")
private String title;
@XmlElement(name="Author")
private String author;
}
questions
How can I resolve the error? Are my POJOs not setup correct? If so, how should I re-structure the POJOs?
There are multiple
Author
in the xml. How can I map them to an Array or list of sort.