java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap #41
Description
i use retrofit + rxjava + rxcache in my project,and the response json data format is:
{"data":{},"status":200}
i define a BaseResponse.class ps : data is a object not list:
public class BaseResponse<T> { public int status; public T data; }
i define a cache interface method :
@LifeCache(duration = 20, timeUnit = TimeUnit.MINUTES) Observable<Reply<BaseResponse<UserBasicInfoResponse>>> loadUserBasicInfo(Observable<BaseResponse<UserBasicInfoResponse>> userBasicInfoResponseObservable , DynamicKey userId , EvictProvider evictProvider);
when racache load from memory it's ok,but raCache load from disk an error has occurred(java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap ),I don't know how to solve this question.
when i debug I find diskCache lose type "UserBasicInfoResponse", do you have any advice about it ?
thinks!
Activity
VictorAlbertos commentedon Jun 22, 2016
Don't save the object
BaseResponse
, instead, usemap
operator to transform it toUserBasicInfoResponse
prior to calling RxCache.androidle commentedon Jun 22, 2016
Thinks so much for your quick reply!
but I still have some confused ,since data from net is
Observable<BaseResponse<UserBasicInfoResponse>>
,how can I saveUserBasicInfoResponse
instead ofBaseResponse<UserBasicInfoResponse>
, do you give me some detail advices ?thanks!
my core code about it as below
This is the core method:
This is the net API
This is the cache interface method
VictorAlbertos commentedon Jun 22, 2016
The endpoint should be
And you just need to apply the map operator to transform the data. I suggest to you to learn a little more rxjava before attempting to use RxCache, or any reactive library for that matters. ;)
androidle commentedon Jun 23, 2016
OK,thank you so much!
guobinAndroid commentedon Dec 23, 2016
but if i want to save just baseResponse, how can i do @VictorAlbertos
ml-bright commentedon Dec 24, 2016
this is my method to avoid use
BaseResponse<T>
@VictorAlbertos help me that whether this can sovle problem
#73