JakeWharton/retrofit2-kotlinx-serialization-converter

Help with converter

saintjab opened this issue · 1 comments

@JakeWharton thanks for this library. I just tried to use Kotlin serialization to replace Gson however I am having issues using it for RealmList. Am getting error
kotlinx.serialization.SerializationException: Can't locate argument-less serializer for class io.realm.RealmList and I think it might be issue with the converter am using. Below is a code

open class Person(var name: String = "", var social : RealmList<Social> = null, var id: String = "") : RealmObject(), Parcelable

@Serializable
@Parcelize
open class Social(var name: String = "", var category : String = "", var id: String = "") : RealmObject(), Parcelable

override fun loadPersons(): Single<Person> {
    return communicationContext.personApi
        .getPersonsObservable()
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .doOnError {
            Log.e(TAG, "Load error $it")**// Error here : kotlinx.serialization.SerializationException: Can't locate argument-less serializer for class io.realm.RealmList**
        }
        .doOnSuccess {
            Log.e(TAG, "Success size ${it.size}")
        }
} 

fun provideRetrofit(okHttpClient: OkHttpClient, urlProvider :
    URLProvider): Retrofit {
    val contentType = MediaType.get("application/json")
    return Retrofit.Builder()
        .baseUrl(urlProvider.getApiBaseUrl()!!)
        .addConverterFactory(Json.asConverterFactory(contentType))
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .client(okHttpClient)
        .build()
}```

Do I need to write a custom serializer/converter for the Realmlist? If so any help will be appreciated.  Thanks

You probably need a custom converter, yes, but you're far better seeking help on StackOverflow or the kotlinx.serialization issue tracker. This library just connects kotlinx.serialization to Retrofit, and you'll have these problems regardless of how you end up using kotlinx.serialization–it's not specific to using Retrofit or specific to this library's integration of the two. Additionally, I don't know anything about Realm so I'm not sure even how to create such a converter.