我可以在 JAX-RS 休息服务中使用 String 对象,但不能使用 POJO 对象。我应该如何配置 POJO 类以使其能够用作 JAX-RS 休息服务中的资源?
DTO 类
public class RestServiceDTO {
private String groupId;
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId)
this.groupId = groupId;
}
@Override
public String toString() {
return "RestServiceDTO [groupId=" + groupId + "]";
}
}
休息服务:
@Component(
immediate = true,
property = {
JaxrsWhiteboardConstants.JAX_RS_APPLICATION_BASE + "=/greetings",
},
service = Application.class
)
public class RestServiceApplication extends Application {
public Set<Object> getSingletons() {
return Collections.<Object>singleton(this);
}
@POST
@Path("/post")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String test(RestServiceDTO dto) {
String groupid = dto.getGroupId();
return "{'groupid':'" + groupid + "'}";
}
}
错误:
2019-02-12 13:33:58.021 错误 [http-nio-8080-exec-1][JAXRSUtils:83] 没有为 com.dto.RestServiceDTO 类找到消息正文阅读器,ContentType: application/json