RoboSpice with Gson and Realm

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 08:18:53

I used Robospice with Retrofit and Realm.

I solved it by overriding createConverter() in my Service class that extends RetrofitGsonSpiceService. Unfortunately, I can't say more clearer because I haven't used GsonSpringAndroidSpiceService.

So in my Service class it looked like this:

@Override
protected Converter createConverter() {
    Gson gson = 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();

    return new GsonConverter(gson);
}

So the idea is to find where Gson can be initialized with default configuration. And that's why I passed the above mentioned configuration to Retrofit also.

new RestAdapter.Builder()
               .setConverter(new GsonConverter(gson))
               .build();

Hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!