LinkedTreeMap cannot be cast Gson

后台返回数据,正常返回data可以,错误返回就为null了 就会出现LinkedTreeMap cannot be cast 这种异常。

public class HttpResult<T> {
    public int code;
    public String msg;
    public T data;
}
  public class HttpResultFunc<T> implements Function<HttpResult<T>, T> {
        @Override
        public T apply(HttpResult<T> httpResult) throws Exception {
            if (httpResult.code != HTTP_SUCCESS) {
                throw new ApiException(httpResult.code, httpResult.msg);
            }
            if (httpResult.data == null) {
                httpResult.data = (T) "";
            }
            return httpResult.data;
        }
    }
  @FormUrlEncoded
    @POST(TU_UPDATEUSER)
    Flowable<HttpResult<Object>> updateUser(@Field("token") String token, @Field("content") String content, @Field("type") String type);

//关键代码 返回数据处理

 String json = GsonUtil.GsonString(o);
                UserBean userRegisterBean = GsonUtil.GsonToBean(json,UserBean.class);
                UserInfoBean.getInstance().setAccess(userRegisterBean);

猜你喜欢

转载自blog.csdn.net/yujunlong3919/article/details/81207048