我正在将现有的Jersey 1.x代码迁移到2.x,并且在执行以下代码时遇到问题。
泽西岛代码:
superproject
EmployeeDetail类:
public String getEmployeeDetail(long empId) {
String empName = null;
String url = String.format("%s/%d/", "http://localhost:8080/emp/detail", empId);
UriBuilder builder = UriBuilder.fromUri(url);
WebTarget webtarget = client.target(builder.build());
EmployeeDetail empDetail = webtarget.request("application/x-java-serialized-object").header("Cache-Control", "no-cache").get(EmployeeDetail.class);
if(empDetail.getName() != null) {
empName = empDetail.getName();
}
return empName;
}
例外:
@XmlRootElement(name="employeeDetail")
public class EmployeeDetail {
String name;
String age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
经过一些研究,尝试了以下内容,结果出现了同样的错误。
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/x-java-serialized-object;class=com.client.response.EmployeeDetail,
type=class com.client.response.EmployeeDetail, genericType=class com.client.response.EmployeeDetail.