I have two bean directories, one for request beans and the other for response beans, each containing their own ObjectMapper class.
I was able to succecssfully marshall my XML Beans (for the request) to a XML String before sending it off using the following below.
JAXBElement<RequestblockType> requestblock = objectFactory.createRequestblock(requestblockType);
m.marshal(requestblock, writer);
// output string to console
byte[] bytes = writer.toString().getBytes(Charset.forName("UTF-8"));
I got my response back from server as an xml string and now trying to unmarshall back into my objects.
JAXBContext jaxbContext = JAXBContext.newInstance(ResponseblockType.class);
StringReader reader = new StringReader(xmlString);
jaxbContext.createUnmarshaller().unmarshal(reader); //this line throws Exception
um.unmarshal(reader);
On the line specified i get following exception:
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"responseblock"). Expected elements are <{}responseblockType>
Below is my XML and the top level bean class which is off the most 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>
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 anybody let me know where im going wrong? I can supply more information if possible. I saw from other post that adding an @XMLRootElement to my top level bean response class could help but it hasnt. Beside i didnt have to do this for my request when marshalling.
No comments:
Post a Comment