球衣项目中的类别施放异常?(Class cast exception in jersey project?)
我有一个球衣休息项目和一个新手问题。 从服务器端:
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为什么我不能在客户端获取错误字符串? 这是正确的(String)response.getEntity()吗?
I have a jersey rest project and one newbie question. From server side:
throw new WebApplicationException(Response.status(Status.NOT_FOUND) .entity("no access token found").build());From client side
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; }Problem is
java.lang.ClassCastException: org.glassfish.jersey.client.HttpUrlConnector$1 cannot be cast to java.lang.StringWhy I can't get error string on client side ? Is this correct (String) response.getEntity() for that ?
最满意答案
你需要使用response.readEntity(String.class)而不是(String) response.getEntity()
You need to use response.readEntity(String.class) instead of (String) response.getEntity()
更多推荐
发布评论