Java / JAXB麻烦拆封包含List的对象?

问题描述

我在整理来自基于SOAP的Web服务的响应时遇到了一些困难。.有一个User(基于WSDL自动生成)对象,其中包含一个列表List,其中列表似乎有问题,并且我收到以下错误

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing Failed; nested exception is org.springframework.ws.soap.client.soapFaultClientException: Unmarshalling Error: unexpected element (uri:"",local:"affiliations"). Expected elements are (none)

我能到达这里的任何帮助对我来说意味着一个世界

代码如下:

        var userRequest = new GetUser();
        var wrappedUserRequest = objectFactory.createGetUser(userRequest);

        userRequest.setArg0((long) id);

        var response = (JAXBElement<GetUserResponse>) getwebservicetemplate()
                .marshalSendAndReceive(nissyUri,wrappedUserRequest);

        return response.getValue().getReturn();

.marshalSendAndReceive方法失败。这是使用的java类

@XmlAccessorType(XmlAccesstype.FIELD)
@XmlType(name = "user",propOrder = {
    "affiliations","comment","currentAffiliations","currentRoles","disabled","domain","email","firstName","id","lastModifiedBy","lastName","middleName","password","passwordDate","passwordHistory","phone","position","region","roles","treatmentCenterName","username"
})
public class User {

    @XmlElement(nillable = true)
    protected List<Affiliation> affiliations;
    protected String comment;
    protected String currentAffiliations;
    protected String currentRoles;
    protected boolean disabled;
    protected String domain;
    protected String email;
    protected String firstName;
    protected Long id;
    protected String lastModifiedBy;
    protected String lastName;
    protected String middleName;
    protected String password;
    @XmlSchemaType(name = "dateTime")
    protected XMLGregorianCalendar passwordDate;
    protected String passwordHistory;
    protected String phone;
    protected String position;
    protected Integer region;
    @XmlElement(nillable = true)
    protected List<Role> roles;
    protected String treatmentCenterName;
    protected String username;
}

    public List<Affiliation> getAffiliations() {
        if (affiliations == null) {
            affiliations = new ArrayList<Affiliation>();
        }
        return this.affiliations;
    }

// More setters and getters..

@XmlAccessorType(XmlAccesstype.FIELD)
@XmlType(name = "getUserResponse",propOrder = {
    "_return"
})
public class GetUserResponse {

    @XmlElement(name = "return")
    protected User _return;

}

@XmlAccessorType(XmlAccesstype.FIELD)
@XmlType(name = "affiliation",propOrder = {
    "account","attributes","organizationId","primary","type"
})
public class Affiliation {

    @XmlElementRef(name = "account",type = JAXBElement.class,required = false)
    protected JAXBElement<String> account;
    @XmlElementRef(name = "attributes",required = false)
    protected JAXBElement<String> attributes;
    protected Long id;
    protected Long organizationId;
    protected boolean primary;
    protected String type;

 public JAXBElement<String> getAccount() {
        return account;
    }
// Getters and setters etc..

@XmlAccessorType(XmlAccesstype.FIELD)
@XmlType(name = "getUserResponse",propOrder = {
    "_return"
})
public class GetUserResponse {

    @XmlElement(name = "return")
    protected User _return;

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)