package com.itstyle.mdm.utils.model; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @JacksonXmlRootElement(localName = "soap:Envelope") public class SoapEnvelopeProduct { @JacksonXmlProperty(localName = "Body") private SoapBody body; // getters and setters public SoapBody getBody() { return body; } public void setBody(SoapBody body) { this.body = body; } public static String getResJson(String xml){ XmlMapper xmlMapper = new XmlMapper(); SoapEnvelopeProduct envelope = null; String jsonStr=""; try { envelope = xmlMapper.readValue(xml, SoapEnvelopeProduct.class); jsonStr = envelope.getBody().getReceiveTCGResponse().getReceiveTCGResult().trim(); } catch (Exception e) { jsonStr="{\"error\":\""+e.getMessage()+"\"}"; } return jsonStr; } } class SoapBody { @JacksonXmlProperty(localName = "ReceiveTCGResponse") @JacksonXmlElementWrapper(useWrapping = false) private ReceiveTCGResponse receiveTCGResponse; // getters and setters public ReceiveTCGResponse getReceiveTCGResponse() { return receiveTCGResponse; } public void setReceiveTCGResponse(ReceiveTCGResponse receiveTCGResponse) { this.receiveTCGResponse = receiveTCGResponse; } } @JacksonXmlRootElement(localName = "ReceiveTCGResponse", namespace = "http://www.hitachi.com/HITPHAMS") class ReceiveTCGResponse { @JacksonXmlProperty(localName = "ReceiveTCGResult") private String receiveTCGResult; // getters and setters public String getReceiveTCGResult() { return receiveTCGResult; } public void setReceiveTCGResult(String receiveTCGResult) { this.receiveTCGResult = receiveTCGResult; } }