galex
05/05/2019, 4:27 AMkotlin.NotImplementedError: An operation is not implemented: Obtaining serializer from KClass is not available on native due to the lack of reflection. Use .serializer() directly on serializable class.
at 0 mu51k-ios 0x0000000108ff28a5 kfun:kotlin.Error.<init>(kotlin.String?)kotlin.Error + 21
at 1 mu51k-ios 0x00000001090f8bd5 kfun:kotlin.NotImplementedError.<init>(kotlin.String)kotlin.NotImplementedError + 21
at 2 mu51k-ios 0x0000000109134802 kfun:kotlinx.serialization.compiledSerializer@kotlin.reflect.KClass<#GENERIC_kotlin.Any>.()Generic + 226
at 3 mu51k-ios 0x00000001091342c1 kfun:kotlinx.serialization.serializer@kotlin.reflect.KClass<#GENERIC_kotlin.Any>.()Generic + 97
at 4 mu51k-ios 0x000000010913e9b0 kfun:kotlinx.serialization.modules.getContextualOrDefault@kotlinx.serialization.modules.SerialModule.(kotlin.reflect.KClass<#GENERIC_kotlin.Any>)Generic + 144
at 5 mu51k-ios 0x000000010913dbf8
It’s weird because the type response the API returns is indeed registered:
actual val networkHttpClient: HttpClient
get() = HttpClient {
install(JsonFeature) {
serializer = KotlinxSerializer().apply {
setMapper(CheckEmailResponse::class, CheckEmailResponse.serializer())
setMapper(AuthResponse::class, AuthResponse.serializer())
setMapper(ActionResponse::class, ActionResponse.serializer())
}
}
}
Does this error mean the http-client doesn’t know what to do with String? Are we supposed to register simple types ourselves?val address = Url("$baseUrl/$API/$AUTH/$CREATE")
GlobalScope.launch(backgroundDispatcher) {
val result: AuthResponse = <http://networkHttpClient.post|networkHttpClient.post> {
url(address.toString())
body = TextContent(
Json.stringify(CreateAccountParameters(email, password, reEnterPassword)),
contentType = ContentType.Application.Json
)
}
GlobalScope.launch(foregroundDispatcher) {
block(result)
}
}
Any help would be greatly appreciated!Lawik
05/06/2019, 8:06 AMgalex
05/06/2019, 10:59 AM@Serializable
data class AuthResponse(val token: String, val userId: Int? = null)
Json.stringify(CreateAccountParameters(email, password, reEnterPassword))
instead of Json.stringify(CreateAccountParameters.serializer(), CreateAccountParameters(email, password, reEnterPassword)),
. Gosh that was a difficult one to find…sandwwraith
05/14/2019, 8:17 PMUse .serializer() directly on serializable class.
, or was it missing?
Unfortunately, there is a very limited possibilities to enhance this since reflection is almost impossible on Nativegalex
05/15/2019, 9:24 AMJson.stringify(…)
. Understood, so it’s better to always use .serializer
and if so, better to do it in the common code already for all platforms. correct?sandwwraith
05/15/2019, 9:34 AMgalex
05/15/2019, 2:35 PM