0

我尝试在 linux 中从 curl 调用 REST Web 服务,也使用 jersey
然后它返回

A message body reader for Java type, class mypackage.UserGroupsData, and MIME media type, application/json, was not found

Mappign 类是

public class UserGroupsData {
private int id;
private String name;    
public int getId() {
    return id;
} public void setId(int id) {
   this.id = id;
}public String getName() {
    return name;
}public void setName(String name) {
    this.name = name;
} public int getId() {
    return id;
}}

我的 POST 方法 ID

@POST
@Path("/getQualifiedNumbers")
@Produces("application/json")
@Consumes("application/json")
public Response getQualifiedNumbers(UserGroupsData userGroup){            
    return Response.status(201).entity(userGroup).build();        
}

我曾经调用的卷曲命令是

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":"1","name":"e"}' http://localhost:8080/url/getQualifiedNumbers

服务器是码头

谢谢

4

1 回答 1

0

尝试在您的课程中添加注释“@XmlRootElement”。它应该变成这样:

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class UserGroupsData {
private int id;
private String name;    
public int getId() {
    return id;
} public void setId(int id) {
   this.id = id;
}public String getName() {
    return name;
}public void setName(String name) {
    this.name = name;
} public int getId() {
    return id;
}}
于 2012-12-05T10:38:34.480 回答