Java 泽西岛项目中的类强制转换异常?
我有一个新泽西休息项目和一个新手问题。从服务器端:Java 泽西岛项目中的类强制转换异常?,java,rest,jersey,Java,Rest,Jersey,我有一个新泽西休息项目和一个新手问题。从服务器端: throw new WebApplicationException(Response.status(Status.NOT_FOUND) .entity("no access token found").build()); 从客户端 else if (Status.fromStatusCode(response.getStatus()) == Status.NOT_FOUND || Status.fromStatusCode(r
throw new WebApplicationException(Response.status(Status.NOT_FOUND)
.entity("no access token found").build());
从客户端
else if (Status.fromStatusCode(response.getStatus()) == Status.NOT_FOUND || Status.fromStatusCode(response.getStatus()) == Status.GONE)
{
final VerifyTokenResponse verifyTokenResponse = new VerifyTokenResponse();
verifyTokenResponse.setError((String) response.getEntity());
return verifyTokenResponse;
}
问题是
java.lang.ClassCastException: org.glassfish.jersey.client.HttpUrlConnector$1 cannot be cast to java.lang.String
为什么我无法在客户端获取错误字符串?这是正确的(字符串)响应.getEntity()吗?您需要使用
response.readEntity(String.class)
而不是(字符串)响应.getEntity()