ktor_serialization_.txt
# serialization
j
ktor_serialization_.txt
r
What platform are you running this code on?
j
Common module
r
That’s not a platform
j
Android+iOS
r
Use
setMapper
instead of
register
j
Hmm I tried that also same issue
r
Oh, it’s a list. Top level lists aren’t supported because “they’re not proper json” or something like that
The workaround is a custom deserializer
Like
ContentsResponseList(val list: ContentsResponse)
and then you use this type as return type and have a custom deserializer which returns the list inside directly
j
🤔 This works ok: Json.nonstrict.parse(ContentsResponse.serializer.list, stringResponse)
And then you use
get<Foobars>(...).list
It’s not a problem with the deserialization, it’s a problem with finding the deserializer
j
Great thanks. I'll try that out and let you know
Will this method perform differently than retrieving and parsing the string?
KN serialization doesn't support io streams yet right?
s
@e5l
j
val httpClient = HttpClient { install(JsonFeature) { serializer = KotlinxSerializer(Json.nonstrict).apply { setMapper(ContentResponseList::class, ContentResponseList.Companion) } } } internal class ContentResponseList(val list: List<ContentsResponse>) { @Serializer(ContentsResponse::class) companion object : KSerializer<ContentResponseList> { override fun serialize(encoder: Encoder, obj: ContentResponseList) = ContentsResponse.serializer().list.serialize(encoder, obj.list) override val descriptor = StringDescriptor.withName(ContentResponseList::class.simpleName!!) } }
Same error
io.ktor.client.call.NoTransformationFoundException: No transformation found: class kotlinx.coroutines.io.ByteBufferChannel -> class kotlin.collections.List