gpt4 book ai didi

javax.xml.bind.UnmarshalException : unexpected element even if @XmlRootElement is added

转载 作者:太空宇宙 更新时间:2023-11-04 06:18:23 25 4
gpt4 key购买 nike

在 SoapUI 中我遇到了这个异常

<faultstring>Unmarshalling Error: unexpected element (uri:"http://ws.soap.rd.pl", local:"User"). Expected elements are &lt;{}User></faultstring>

我真的不知道为什么会出现这个问题。我已经尝试过 Stack 中给出的 trip 但仍然找不到答案。添加了@XmlRootElement,所以我真的很困惑。

请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.soap.rd.pl/" xmlns:ws1="http://ws.soap.rd.pl">
<soapenv:Header/>
<soapenv:Body>
<ws:updateUser>
<!--Optional:-->
<ws1:User>
<ID>?</ID>
<!--Optional:-->
<Imie>?</Imie>
<!--Optional:-->
<Nazwisko>?</Nazwisko>
<!--Optional:-->
<ws1:Adres>
<!--Optional:-->
<id>?</id>
<!--Optional:-->
<Ulica>?</Ulica>
<!--Optional:-->
<Miasto>?</Miasto>
</ws1:Adres>
</ws1:User>
</ws:updateUser>
</soapenv:Body>
</soapenv:Envelope>

我的 dto:

@XmlRootElement(name = "Adres", namespace = "http://ws.soap.rd.pl")
@XmlAccessorType(XmlAccessType.FIELD)
public class AddressDto {

@XmlElement(name = "id", required = false)
public Long id;

@XmlElement(name = "Ulica", required = false)
public String street;

@XmlElement(name = "Miasto", required = false)
public String city;

@Override
public String toString() {
return "AddressDto [street=" + street + ", city=" + city + "]";
}

}

第二个:

@XmlRootElement(name = "User", namespace = "http://ws.soap.rd.pl")
@XmlAccessorType(XmlAccessType.FIELD)
public class UserDto {

@XmlElement(name = "ID")
public long id;

@XmlElement(name = "Imie", required = false)
public String firstName;

@XmlElement(name = "Nazwisko", required = false)
public String lastName;

@XmlElement(name = "Adres", required = false)
public AddressDto addressDto;

@Override
public String toString() {
return "UserDto [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", addressDto=" + addressDto + "]";
}

}

如果您需要我的 webService 定义:

@WebService(endpointInterface = "userService", serviceName = "userService", name = "userServive")
public interface UserService {

@WebMethod
public void updateUser(@WebParam(name = "User") UserDto user);
}

最佳答案

尝试将 targetNamespace 添加到您的 @WebParam:

@WebMethod
public void updateUser(
@WebParam(name = "User", targetNamespace = "http://ws.soap.rd.pl")
UserDto user);

关于javax.xml.bind.UnmarshalException : unexpected element even if @XmlRootElement is added,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27770557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com