Help us understand the problem. What is going on with this article?

RealmとGsonで10分くらいハマった話。あと解決方法。

More than 3 years have passed since last update.

Realmを導入したら通信時にこんなログがで続けてハングアップした。

concurrent mark sweep GC freed 76220(1711KB) AllocSpace objects, 77(2MB) LOS objects, 29% free, 8MB/12MB, paused 5.798ms total 50.613ms

RealmObjectの内容をGsonがJSON文字列にしようとしてるいるのが原因でした。

不便ですがJson化したいオブジェクトはRealmObjectにできない。。。
かとおもいきや。

    public static Gson gson() {
        return new GsonBuilder()
                .setExclusionStrategies(new ExclusionStrategy() {
                    @Override
                    public boolean shouldSkipField(FieldAttributes f) {
                        return f.getDeclaringClass().equals(RealmObject.class);
                    }

                    @Override
                    public boolean shouldSkipClass(Class<?> clazz) {
                        return false;
                    }
                })
                .create();
    }

解決できました。

参考

Merging Realm object & Gson object
- http://stackoverflow.com/questions/26275143/merging-realm-object-gson-object

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした