我尝试从curl调用REST web服务,在linux中,也使用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
服务器是码头
谢谢
答案 0 :(得分: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;
}}