Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible store complex objects? #125

Closed
dsdebastiani opened this issue Jan 12, 2016 · 5 comments
Closed

Is it possible store complex objects? #125

dsdebastiani opened this issue Jan 12, 2016 · 5 comments

Comments

@dsdebastiani
Copy link

I'm trying to store a complex object (object with custom class atributes, and lists), but my app is freezing when it's executed Hawk.put("KEY", coplexObject);. Only freezing. No crashing, no closing, nothing.

The object which I'm trying to store is like:

public class ComplexObject {
  private AnotherComplexObject attr;
  private List<AnotherComplexObject_2> listAttr;
  private long attr2;

// getters and setters
...
}

This object come from a REST API and I'm using Retrofit with Gson. I'd like to just store it.

Does Hawk support this kind of objects?

Thanks for help.

@orhanobut
Copy link
Owner

Hawk uses gson to convert object to string. There shouldn't be any problem with that. I could check this one with test case to see if it works. There might be different reason. Maybe the object contains too much data and it takes a little while to convert it. Can you try with a background worker? Or if you put the exact object here, I can try as well with a test case.

@ningxz
Copy link

ningxz commented Mar 15, 2016

i also meet the same problem, my complex object is come from a REST API and i using Retrofit with gson, the response json string like this:

{
"code": 200,
"message": "success",
"requestUri": "/v1/banners/list",
"data": [
{
"bannerId": 2,
"title": "中文超级长标题的test看看这个标题够不够长啊 ",
"displayorder": 1,
"imageUrl": "http://xxxxx/group2/M00/5F/EA/rBADO1Yco_GAWjhTAANNzCyLAVI134.png"
},
{
"bannerId": 6,
"title": "333",
"displayorder": 2,
"imageUrl": "http://xxxx/group2/M00/5F/EA/rBADO1YcouaAd5pTAAGIDOTG3nA618.png"
}
],
extra: {
"customParam": "",
"cacheUpdateTime": -1
}
}

I use two object to covert this json string:

public class BaseEntity<T extends DataSupportBase> implements Serializable {

    private int code;
    private String message;
    private String requestUri;
    private List<T> data;
    private Object extra;
}

public class BannerInfo extends DataSupportBase {

    private int bannerId;
    private String title;
    private int displayorder;
    private String imageUrl;
}

then, in my code i use BaseEntity to encapsulation it, print it

BaseEntity{code=200, message='success', requestUri='/banners/list', data=[BannerInfo{bannerId=34, title='长图长图-简约不简单', displayorder=21, imageUrl='http://xxxx/group2/M00/34/02/rBADO1aOOwGAIqbnAApB_alyZmo924.png'}, BannerInfo{bannerId=98, title='khz-测试-0112-1', displayorder=6291461, imageUrl='http://xxxx/group2/M00/3B/1E/rBADO1aU4d-AYWhFAAvWFkcZHjA200.png'}], extra={customParam=, cacheUpdateTime=-1.0}}

when i use Hawk.put("banner", banner)

when i use Hawk.get("banner") to get the store object, it return

BaseEntity{code=200, message='success', requestUri='/banners/list', data=[{bannerId=34.0, displayorder=21.0, imageUrl=http://xxxx/group2/M00/34/02/rBADO1aOOwGAIqbnAApB_alyZmo924.png, title=长图长图-简约不简单, baseObjId=0.0}, {bannerId=98.0, displayorder=6291461.0, imageUrl=http://xxxx/group2/M00/3B/1E/rBADO1aU4d-AYWhFAAvWFkcZHjA200.png, title=khz-测试-0112-1, baseObjId=0.0}], extra={customParam=, cacheUpdateTime=-1.0}}

then there is a error : error ........java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to BannerInfo

there are some different between before stored and after stored , maybe you can test it with these objects, wish to recieve your answer as soon as possible

@orhanobut
Copy link
Owner

Sorry for very late response. Is this still an issue?

@orhanobut
Copy link
Owner

Closing this issue for now, we can definitely re-open if needed

@anderson-silva-ifood
Copy link

Yes, some as me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants