1 year ago

#70464

test-img

Shoxrux Sindarov

how to fix while converting xml to java object is response null

Hi guys i am trying to convert soap xml to java classes fields but response gives null values into targeted class fields. I haven't worked with soap before, I work with soap for the first time, so I did a bit of google in 2 days and tried to use it. Attached screenshots from intellij debug

debuging-screenshots

It is a SOAP XML file. In fact this is the value of xml that comes to me as a response from another API because I got it via SOAPUI because I had a request for it. So I tried to convert this xml in a new project without working on a real project. I also mentioned the classes in this project below

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soapenv:Body>
            <ns1:queryTransactionHistoryResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:IssuingWS/binding">
                <ResponseInfo>
                    <response_code>0</response_code>
                    <error_description xsi:nil="true"/>
                    <error_action xsi:nil="true"/>
                    <EXTERNAL_SESSION_ID>TEST111_20211111111111212201191210111511</EXTERNAL_SESSION_ID>
                </ResponseInfo>
                <Details>
                    <row>
                        <item>
                            <name>CARD_ACCT</name>
                            <value>0901095000004266</value>
                        </item>
                        <item>
                            <name>ACCOUNT_NO</name>
                            <value>8186</value>
                        </item>
                        <item>
                            <name>CL_ACCT_KEY</name>
                            <value>8096</value>
                        </item>
                        <item>
                            <name>CLIENT</name>
                            <value>00003660</value>
                        </item>           
                  
                    </row>  
                    <row>
                        <item>
                            <name>CARD2_ACCT</name>
                            <value>0901095000004266</value>
                        </item>
                        <item>
                            <name>ACCOUNTSSO</name>
                            <value>8186</value>
                        </item>
                        <item>
                            <name>CL_ACCT_KEY22</name>
                            <value>8096</value>
                        </item>
                        <item>
                            <name>SOMENAME</name>
                            <value>00003660</value>
                        </item> 
                  
                    </row>           
                </Details>
            </ns1:queryTransactionHistoryResponse>
        </soapenv:Body>
    </soapenv:Envelope>

It is rootclass parent class got it from the name after ns1 in the XML, but I don't know if the situation I'm using is correct and one of the things I don't understand is the xmlns.

package uz.paynet.test.Xml;

import lombok.ToString;

import javax.xml.bind.annotation.*;

@ToString
@XmlRootElement(namespace = "urn:IssuingWS/binding")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "queryTransactionHistoryResponse")
public class QueryTransactionHistoryResponse {
    @XmlElement(name = "ResponseInfo", required = true,nillable = true)
    private ResponseInfo responseInfo;

    @XmlElement(name = "Details", required = true,nillable = true)
    private Details details;

    public QueryTransactionHistoryResponse() {
    }

    public QueryTransactionHistoryResponse(ResponseInfo responseInfo, Details details) {
        this.responseInfo = responseInfo;
        this.details = details;
    }

    public ResponseInfo getResponseInfo() {
        return responseInfo;
    }

    public void setResponseInfo(ResponseInfo responseInfo) {
        this.responseInfo = responseInfo;
    }

    public Details getDetails() {
        return details;
    }

    public void setDetails(Details details) {
        this.details = details;
    }
}

it is my ResponseInfo class but this class get value you show on screenshop

package uz.paynet.test.Xml;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

@XmlAccessorType(XmlAccessType.FIELD)
public class ResponseInfo{

    @XmlElement(name = "response_code")
    private int responseCode;

    @XmlElement(name = "error_description",nillable = true)
    private String errorDescription;

    @XmlElement(name="error-action",nillable = true)
    private String errorAction;

    @XmlElement(name = "EXTERNAL_SESSION_ID")
    private String externalSessionId;

    public ResponseInfo(int responseCode, String errorDescription, String errorAction, String externalSessionId) {
        this.responseCode = responseCode;
        this.errorDescription = errorDescription;
        this.errorAction = errorAction;
        this.externalSessionId = externalSessionId;
    }

    public ResponseInfo() {
    }

    public int getResponseCode() {
        return responseCode;
    }

    public void setResponseCode(int responseCode) {
        this.responseCode = responseCode;
    }

    public String getErrorDescription() {
        return errorDescription;
    }

    public void setErrorDescription(String errorDescription) {
        this.errorDescription = errorDescription;
    }

    public String getErrorAction() {
        return errorAction;
    }

    public void setErrorAction(String errorAction) {
        this.errorAction = errorAction;
    }

    public String getExternalSessionId() {
        return externalSessionId;
    }

    public void setExternalSessionId(String externalSessionId) {
        this.externalSessionId = externalSessionId;
    }
}

this is Details class which Covers Row class

package uz.paynet.test.Xml;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import java.util.List;

@XmlAccessorType(XmlAccessType.FIELD)
public class Details{

    @XmlElement(name = "row")
    List<Row> rowList;

    public Details() {
    }

    public Details(List<Row> rowList) {
        this.rowList = rowList;
    }

    public List<Row> getRowList() {
        return rowList;
    }

    public void setRowList(List<Row> rowList) {
        this.rowList = rowList;
    }
}

and last is Row class which covered value and name which i need to get xml value and name

package uz.paynet.test.Xml;

import javax.xml.bind.annotation.*;
import java.io.Serializable;


@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(namespace = "urn:IssuingWS/binding")
public class Row {

    @XmlElement(name = "name")
    public String name;

    @XmlElement(name = "value")
    private String value;

    public Row(String name, String value) {
        this.name = name;
        this.value = value;
    }

    public Row() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}

java

xml

soap

jaxb

0 Answers

Your Answer

Accepted video resources