zhou-you / RxEasyHttp

本库是一款基于RxJava2+Retrofit2实现简单易用的网络请求框架,结合android平台特性的网络封装库,采用api链式调用一点到底,集成cookie管理,多种缓存模式,极简https配置,上传下载进度显示,请求错误自动重试,请求携带token、时间戳、签名sign动态配置,自动登录成功后请求重发功能,3种层次的参数设置默认全局局部,默认标准ApiResult同时可以支持自定义的数据结构,已经能满足现在的大部分网络请求。
Apache License 2.0
3.13k stars 615 forks source link

请问这种数据结构怎么搞 #131

Closed Blizzard-liu closed 5 years ago

Blizzard-liu commented 5 years ago

我想把分页信息单独抽出来 传入泛型 然后解析不了报错

public class BaseEntity extends ApiResult implements Serializable {

/**
 * 扩展字段
 * 0:data为对象
 * 1:data为集合
 * 2:date为空或者null字段
 */
public int dataType;

public int getDataType() {
    return dataType;
}

public void setDataType(int dataType) {
    this.dataType = dataType;
}

public boolean isTokenLose(){
    return getCode()== Constants.Code.ACCESS_TOKEN_EXPIRED;
}

}

/**

####### 父类统一处理:

fun load()    {
subscribe = object : BaseSubscriber<PagingEntity<T>>() {
              override fun onError(e: ApiException) {

              }

              override fun onNext(t: PagingEntity<T>) {

              }
          }
          getRequest().subscribe(subscribe as BaseSubscriber<PagingEntity<T>>)

      }
abstract fun getRequest(): io.reactivex.Observable<PagingEntity<T>>

########

子类实现接口

HttpManager.post(url)
                .upJson(jsonMd5(mutableMap))
                .execute(object : CallClazzProxy<BaseEntity<PagingEntity<RecruitmentListItemEntity>>, PagingEntity<RecruitmentListItemEntity>>(PagingEntity::class.java){})

######################################################

{ "code": 0, "data": { "page": 1, "perpage": 20, "max_page": 1, "has_more": true, "total": "2", "data": [ { "name": "12312", "birth_year": "2004"

        },
        {
            "name": "黄浩",

            "attachment": [
                {
                    "id": "2019011818002165351",
                    "name": null,
                    "size": 38836,
                    "source": "/resume_attachment_download?params=eyJyZXN1bWVfaWQiOiI3NDUiLCJmaWxlX2lkIjoiMjAxOTAxMTgxODAwMjE2NTM1MSIsInR5cGUiOiJzb3VyY2UiLCJ0b2tlbiI6IjI3OTllYzJhYTU5NTk3OTRjMWZjYWI5MGY1YzhjYTk2In0=",
                    "thumb": ""
                }

            ],
            "is_new": "0",
            "resume_id": "745",

            "new_num": 0
        }
    ],
    "extras": []
},
"msg": "success"

}

Blizzard-liu commented 5 years ago

报错信息 Gson解析 com.google.gson.internal.LinkedTreeMap cannot be cast to XXX

zhou-you commented 5 years ago

采用自定义数据结构,Gson解析 com.google.gson.internal.LinkedTreeMap cannot be cast to XXX 表示数据结构没有定义正确 导致解析失败