球衣项目中的类别施放异常?(Class cast exception in jersey project?)

编程入门 行业动态 更新时间:2024-10-28 00:18:10
球衣项目中的类别施放异常?(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.String

Why 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()

更多推荐

本文发布于:2023-08-03 03:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1382917.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:球衣   异常   类别   项目   Class

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!