java - javax.xml.bind.UnmarshalException iccurs when unmarshalling an XML -


i use below code unmarshal xml using jaxb. responsexml contains xml string returned web service call.

    stringreader reader = new stringreader(responsexml);     jaxbcontext = jaxbcontext.newinstance(testresponse.class);     unmarshaller unmarshaller = jaxbcontext.createunmarshaller();     object idresponse = unmarshaller.unmarshal(reader); 

below exception occurs when unmarshalling.

 javax.xml.bind.unmarshalexception   - linked exception:  [exception [eclipselink-25004] (eclipse persistence services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.xmlmarshalexception  exception description: error occurred unmarshalling document  internal exception: java.lang.illegalargumentexception: ] 

someone work on this.

below testresponse class auto generated xsd

@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "", proporder = {     "responsecode",     "responsedescription",     "responsemessage" }) @xmlrootelement(name = "testresponse") public class testresponse {      @xmlelement(required = true)     protected string responsecode;     @xmlelement(required = true)     protected string responsedescription;     protected string responsemessage;       /**      * gets value of responsecode property.      *       * @return      *     possible object      *     {@link string }      *           */     public string getresponsecode() {         return responsecode;     }      /**      * sets value of responsecode property.      *       * @param value      *     allowed object      *     {@link string }      *           */     public void setresponsecode(string value) {         this.responsecode = value;     }      /**      * gets value of responsedescription property.      *       * @return      *     possible object      *     {@link string }      *           */     public string getresponsedescription() {         return responsedescription;     }      /**      * sets value of responsedescription property.      *       * @param value      *     allowed object      *     {@link string }      *           */     public void setresponsedescription(string value) {         this.responsedescription = value;     }      /**      * gets value of responsemessage property.      *       * @return      *     possible object      *     {@link string }      *           */     public string getresponsemessage() {         return responsemessage;     }      /**      * sets value of responsemessage property.      *       * @param value      *     allowed object      *     {@link string }      *           */     public void setresponsemessage(string value) {         this.responsemessage = value;     }   } 

here sample xml

<a:testresponse xmlns:a="http://esm.mtn.co.za/data/commonbusiness/testvalidate">     <a:responsecode>0</a:responsecode>     <a:responsedescription>success</a:responsedescription>     <a:responsemessage>success</a:responsemessage>   </a:testresponse> 

i think namespace in xml causing problem parsing. try specify namespace in package-info.java , mention prefix "a" in there. can check more information here.

you check similar question here


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -