java - "unexpected element" while trying to map XML to POJOs -
i trying map below xml pojos using jaxb can use data in xml, however, i'm getting error below:
! javax.xml.bind.unmarshalexception: unexpected element (uri:"http://webservices.amazon.com/awsecommerceservice/2011-08-01", local:"itemsearchresponse"). expected elements <{}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: complete first season</title> </itemattributes> </item> </items> </itemsearchresponse>
my pojos (getter/setters skipped 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 resolve error? pojos not setup correct? if so, how should re-structure pojos?
there multiple
author
in xml. how can map them array or list of sort.
you need use package level @xmlschema
annotation map namespace qualification model.
package-info.java
@xmlschema( namespace = "http://www.example.org/package", elementformdefault = xmlnsform.qualified) package example; import javax.xml.bind.annotation.xmlnsform; import javax.xml.bind.annotation.xmlschema;
for more information
Comments
Post a Comment