【发布时间】:2015-09-16 07:03:48
【问题描述】:
我有一个使用 Spring 和 CXF 编写的休息服务。方法如下图。
@POST
@Path("/detail")
public StudentResponse getStudentDetails(Student student);
学生班。
@XmlRootElement(name="Student")
public class Student implements Serializable{
...
我可以使用 cxf 客户端调用服务
WebClient client = WebClient.create("http://localhost:8180/oauthserver/service/student/detail");
client.type("application/json").accept("application/json");
Response response =client.post(s);
StudentResponse sr = response.readEntity(StudentResponse.class);
我发布的数据(使用jackson生成json条目)
{
"name" : "input",
"id" : 1,
"marks" : 20.2
}
但在从 PostMan 为 SoapUI 调用服务时,我收到以下错误。
JAXBException occurred : unexpected element (uri:"", local:"name").
Expected elements are <{}Student>.
unexpected element (uri:"", local:"name"). Expected elements are <{}Student>.
我以 POST 方法和上下文类型 RAW 调用。我已将标头值设置为:
Content-Type : application/json
Accept : application/json
但它仍然无法正常工作。有什么指点吗?
【问题讨论】:
-
如果你使用
{ "Student" : { .... } }会发生什么。顺便说一句,我不认为杰克逊被利用了。我想杰克逊不应该有关于 JAXBExceptions 的错误 -
谢谢。在前面添加学生解决了这个问题。