I have this error. When using Retrofit2 ``` Caused...
# android
c
I have this error. When using Retrofit2
Copy code
Caused by: kotlinx.serialization.SerializationException: Serializer for class 'Result' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
        at kotlinx.serialization.internal.PlatformKt.serializerNotRegistered(Platform.kt:32)
        at kotlinx.serialization.SerializersKt__SerializersJvmKt.serializer(SerializersJvm.kt:60)
        at kotlinx.serialization.SerializersKt.serializer(Unknown Source:1)
        at com.jakewharton.retrofit2.converter.kotlinx.serialization.Serializer.serializer(Serializer.kt:24)
        at com.jakewharton.retrofit2.converter.kotlinx.serialization.Factory.responseBodyConverter(Factory.kt:28)
        at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:362)
        at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:345)
        at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:124)
        	... 90 more
Is there any problem?...
Copy code
val serializationJson = Json {
            useAlternativeNames = true
            isLenient = true
            ignoreUnknownKeys = true
        }

        return Retrofit.Builder()
            .baseUrl(baseUrl)
            .client(client.build())
            .addCallAdapterFactory(CoroutineCallAdapterFactory())
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(serializationJson.asConverterFactory("application/json".toMediaType()))
            .build()
c
I think the issue is not in the setup but how you use the serializer. How did you configure the
Result
class? Did you add the Annotation as spotted in the error report?
c
yes. Here's the data class.
Copy code
import kotlinx.serialization.Serializable

@Serializable
data class ManagerLoginResponseBody(
    val id: Int,
    val kiosk: String, // will be removed
    val created: String? = null,
    val modified: String? = null,
    val name: String,
    val mobile: String,
    val role: String,
    val branch: BranchModel,
    val token: String
)
c
But that’s not the
Result
class Form the error.
c
the Result class is from kotlin library
Copy code
@SinceKotlin("1.3")
@JvmInline
public value class Result<out T> @PublishedApi internal constructor(
    @PublishedApi
    internal val value: Any?
) : Serializable {
    // 
}
c
If you use it, you’ll need to create a serializer for it.
c
isn't this part?
.addConverterFactory(serializationJson.asConverterFactory("application/json".toMediaType()))
c
No
c
How can I create a serializer ??
Json.encodeToString
this one..?
c
Please check the documentation of the Kotlinx serializer plug-in. There are plenty of examples how to create a serializer.
1