后台返回数据,正常返回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);