0

The problem I'm facing is a little strange because when I have a normal model class which I use as a responsebody model for retrofit 2 I get some unexpected error, suppose

open class Example : RealmObject(){
    @Json(name = "token")
    var token: String? = null
    @Json(name = "data")
    var data: RealmList<Data>? = null
}

and Data class is

open class Data : RealmObject(){
    @Json(name = "info")
    var info: String? = null
}

My code crashes showing a ClassNotFoundException (I'm running in debug mode), and if remove KotlinJsonAdapterFactory() the crash doesn't happen, but data value becomes absent, ie in debug mode it appear's as if it doesn't exist, ie an object of Example will show only token value, data doesn't exist not even as null, but I need the KotlinJsonAdapterFactory() because I use annonations so the above was just an experiment.

The only solution I found is convert both classes to data classes and it works perfectly(ofcourse I've to remove the RealmObject extension and make RealmList a normal list), but I need to extend RealmObject() class and data classes cannot be open which is needed by Realm db for the model.

So I reverted back to 1.4 removed the KotlinJsonAdapterFactory(), and everything works, even after proguard it seems, so what should I do to upgrade to Moshi 1.5.

Also I have updated something in my example code the data object is a RealmList and probably why it was ignored/not there when the response came was possibly because my RealmListAdapter for Moshi was ignored???

I'll attach snippets of my moshi and retrofit instances

Moshi`instance

Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.add(RealmListAdapter.FACTORY)
.build()

Retrofit instance

Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
.build()

0 Answers0