java - JaxB Unmarshal Exception: javax.xml.bind.UnmarshalException: unexpected element. Where have i gone wrong? -


i have 2 bean directories, 1 request beans , other response beans, each containing own objectmapper class.

i able succecssfully marshall xml beans (for request) xml string before sending off using following below.

    jaxbelement<requestblocktype> requestblock = objectfactory.createrequestblock(requestblocktype);     m.marshal(requestblock, writer);     // output string console     byte[] bytes = writer.tostring().getbytes(charset.forname("utf-8")); 

i got response server xml string , trying unmarshall objects.

    jaxbcontext jaxbcontext = jaxbcontext.newinstance(responseblocktype.class);     stringreader reader = new stringreader(xmlstring);     jaxbcontext.createunmarshaller().unmarshal(reader); //this line throws exception     um.unmarshal(reader); 

on line specified following exception:

javax.xml.bind.unmarshalexception: unexpected element (uri:"", local:"responseblock"). expected elements <{}responseblocktype>

below xml , top level bean class off importance

<?xml version="1.0" encoding="utf-8"?> <responseblock version="3.67">   <requestreference>x5727835</requestreference>    <response type="auth">   <merchant>      <merchantname>merchant1</merchantname>      <orderreference>8900001233</orderreference>      <tid>12341234</tid>      <merchantnumber>00000000</merchantnumber>      <merchantcountryiso2a>gb</merchantcountryiso2a>   </merchant>   <transactionreference>3-9-1598316</transactionreference>   <timestamp>2014-08-18 11:56:40</timestamp>   <acquirerresponsecode>00</acquirerresponsecode>   <operation>      <accounttypedescription>ecom</accounttypedescription>   </operation>   <settlement>      <settleduedate>2014-08-18</settleduedate>      <settlestatus>0</settlestatus>   </settlement>   <billing>      <amount currencycode="usd">3698</amount>      <payment type="visa">         <issuer>test issuer1</issuer>         <pan>1234123412341234</pan>         <issuercountry>us</issuercountry>      </payment>      <dcc enabled="0" />   </billing>   <authcode>test</authcode>   <live>0</live>   <error>      <message>ok</message>      <code>0</code>   </error>   <security>      <postcode>0</postcode>      <securitycode>2</securitycode>      <address>0</address>   </security>    </response> </responseblock> 

package com.test.adapter.payment.test1.client.model.beans.responses;

import javax.xml.bind.annotation.*;

@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "responseblocktype") @xmlrootelement public class responseblocktype {  @xmlelement(required = true) protected string requestreference; @xmlelement(required = true) protected responsetype response; @xmlattribute(name = "version") protected string version;  public string getrequestreference() { return requestreference; } public void setrequestreference(string value) { this.requestreference = value; } public responsetype getresponse() { return response; } public void setresponse(responsetype value) { this.response = value; } public string getversion() { return version; } public void setversion(string value) { this.version = value;  } 

}

can let me know im going wrong? can supply more information if possible. saw other post adding @xmlrootelement top level bean response class hasnt. beside didnt have request when marshalling.

the root element name of serialized xml responseblock differs 1 defined within bean class.

<responseblock version="3.67"> 

but

@xmlrootelement public class responseblocktype 

it should following match annotation:

 <responseblocktype version="3.67">     ...     ...  </responseblocktype> 

or can override default root element name in @xmlrootelement annotation:

@xmlrootelement(name="responseblock") public class responseblocktype    

another issue within xml root element responseblock isn't closed correctly @ end. same problem seems apply element response s opened @ line 4 of xml

 line 4: <response type="auth"> 

but not closed.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -