使用JAXB将Soap XML响应转换为Object Java

时间:2018-10-31 13:47:26

标签: java xml soap jaxb

我有一个响应XML,我需要在其中添加一个Java对象才能使用它,但是当我尝试从中访问某些内容时,此属性为null。 我试图取消编组,但没有成功

接收到的XML主体是这个。

  <ns1:buscaCadastroImobiliarioGeralResponse>
     <return xsi:type="ns1:retornoBuscaCadbciGeral">
        <cadastros SOAP-ENC:arrayType="ns1:cadastros[1]" xsi:type="ns1:listaCadastros">
           <item xsi:type="ns1:cadastros">
              <codigo_cadastro >xsi:type="xsd:string">461954</codigo_cadastro>

执行的代码

BuscaCadastroImobiliarioGeral request = objectFactory.createBuscaCadastroImobiliarioGeral();

            Entrada entrada = new Entrada();
            entrada.setCodigoCadastro("461954");

            request.setEntrada(entrada);

            BuscaCadastroImobiliarioGeralResponse response = (BuscaCadastroImobiliarioGeralResponse) client.callWebService("url", request);

            System.out.println(response.getReturnResponse());

public class SOAPConnector extends WebServiceGatewaySupport{

    public Object callWebService(String url, Object request) {
        return getWebServiceTemplate().marshalSendAndReceive(url, request);
    }

}

问题是当我得到getReturnResponse时,它总是为空。以上是模型的类别

CLASS BuscaCadastroImobiliarioGeralResponse

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "returnResponse"
})
@XmlRootElement(name = "buscaCadastroImobiliarioGeralResponse")
public class BuscaCadastroImobiliarioGeralResponse {

    @XmlElement(name = "return", required = true)
    private ReturnResponse returnResponse;

    public ReturnResponse getReturnResponse() {
        return returnResponse;
    }

    public void setReturnResponse(ReturnResponse returnResponse) {
        this.returnResponse = returnResponse;
    }
}

CLASS ReturnResponse

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "return", propOrder = {
    "cadastros"
})
@XmlRootElement(name = "return")
@XmlSeeAlso(ReturnResponse.class)

public class ReturnResponse {

    @XmlElement(required = true)
    private List<Cadastros> cadastros;


    public List<Cadastros> getCadastros() {
        return cadastros;
    }

    public void setCadastros(List<Cadastros> cadastros) {
        this.cadastros = cadastros;
    }
}

CLASS Cadastros

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "cadastros", propOrder = {
    "item"
})
@XmlRootElement(name = "cadastros")
@XmlSeeAlso(Cadastros.class)
public class Cadastros {

    @XmlElement
    private Item item;

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }
}

relacionado问题:Spring Web service unmarshalling not happening correctly

0 个答案:

没有答案