https://kotlinlang.org logo
#ktor
Title
# ktor
j

Jose A.

01/19/2021, 10:12 AM
After upgrading to 1.5.0 (from 1.4.3) I got this error:
Copy code
Caused by: kotlinx.serialization.SerializationException: Class 'ArrayList' is not registered for polymorphic serialization in the scope of 'Collection'.
Partial stacktrace:
Copy code
kotlinx.serialization.SerializationException: Class 'ArrayList' is not registered for polymorphic serialization in the scope of 'Collection'.
Mark the base class as 'sealed' or register the serializer explicitly.
	at kotlinx.serialization.internal.AbstractPolymorphicSerializerKt.throwSubtypeNotRegistered(AbstractPolymorphicSerializer.kt:103)
	at kotlinx.serialization.internal.AbstractPolymorphicSerializerKt.throwSubtypeNotRegistered(AbstractPolymorphicSerializer.kt:113)
	at kotlinx.serialization.PolymorphicSerializerKt.findPolymorphicSerializer(PolymorphicSerializer.kt:96)
	at kotlinx.serialization.internal.AbstractPolymorphicSerializer.serialize(AbstractPolymorphicSerializer.kt:32)
	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:223)
	at kotlinx.serialization.json.Json.encodeToString(Json.kt:73)
	at io.ktor.serialization.SerializationConverter.convertForSend(SerializationConverter.kt:118)
	at io.ktor.features.ContentNegotiation$Feature$install$2.invokeSuspend(ContentNegotiation.kt:146)
	at io.ktor.features.ContentNegotiation$Feature$install$2.invoke(ContentNegotiation.kt)
The new version forgot how to convert a list?
Copy code
install(ContentNegotiation) {
        val jsonConfig = Json(DefaultJson) {
            encodeDefaults = false
        }

        json(jsonConfig)
    }
This is the way I install the feature (just using `json()`fails too)
Going back to 1.4.3 fixes the error...
e

e5l

01/19/2021, 11:25 AM
Hey @Jose A., thanks for the notice. Could you file an issue?
j

Jose A.

01/19/2021, 11:35 AM
Will do!
r

Rustam Siniukov

01/19/2021, 12:05 PM
@Jose A. Can you please post type of the response here?
j

Jose A.

01/19/2021, 12:26 PM
Copy code
get("/list") {
                val response: Collection<String> = listOf("a", "b")
                call.respond(response)
            }
This triggers the exception. So Collection<String>
I just posted the problem here: https://youtrack.jetbrains.com/issue/KTOR-1795
👍 1
🙏 1
j

Joost Klitsie

01/19/2021, 12:35 PM
Did you try cleaning/invalidating cache?
j

Jose A.

01/19/2021, 12:58 PM
Same result
r

Rustam Siniukov

01/19/2021, 4:16 PM
opened PR with the fix. target - 1.5.1
🙏 1
🎉 1
thanks for the report!
j

Jose A.

01/19/2021, 5:07 PM
Thanks for the fast response!
3 Views