我正在研究Rest Service项目,我正在使用RestEasy implmentation,我的一个要求是一般地实现create(add)服务。以下是用例。
class Person {
private String firstName;
private String lastName;
}
class Student extends Person {
private String college;
private String univerisy;
}
class Employee extends Person {
private String employer;
private String designation;
}
我想为Person(Student,Employee,MovieActor等)的所有子类创建一个create / add rest服务方法。
为了实现这个功能,我创建了下面给出的休息服务方法,但是我得到参数类型不匹配错误
@POST
@Path("/create")
@Consumes(MediaType.APPLICATION_JSON)
public <T extends Person> Response create(@PathParam("type") String type, T person) {
}
访问create方法的客户端程序:
Student student = buildStudent();
//Define the API URI where API will be accessed
ClientRequest request = new ClientRequest("http://myrestservice.com/restservice/rest/student/create/");
//Set the accept header to tell the accepted response format
request.body(MediaType.APPLICATION_JSON, student);
//Send the request
ClientResponse response = request.post(Student.class);
有谁能告诉我如何在休息服务中创建通用的创建方法?
提前致谢。