in a nested Map and I'm using the @contextual method defined in this post:
Copy code
@Serializable
data class Media(
val id: String? = null,
val title: String? = null,
val tracking: Map<String, Map<String, @Contextual Any>> = mapOf(),
)
val json = Json {
ignoreUnknownKeys = true
serializersModule = SerializersModule {
contextual(String.serializer()) // could be an Int
contextual(Int.serializer()) // could be a String
contextual(Boolean.serializer()) // could be a Boolean
}
}
val media = json.decodeFromString(Media.serializer(), MediaResponse.json) //MediaResponse.json is a string
I'm still getting this error
Copy code
kotlinx.serialization.SerializationException: Serializer for class 'Any' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
Am I missing something?
t
turansky
01/29/2021, 11:42 PM
@Contextual
require context for
Any
type (missed in
json
constant)
m
Megan Teahan
01/30/2021, 12:46 AM
@turansky Thanks for the response! I'm still a little unclear on your suggestion of what needs to be added to the json constant. Mostly because
Any
doesn't have its own serializer so I can't do something like
contextual(Any.serializer())
.
t
turansky
01/30/2021, 12:50 AM
AFAIK - you need register custom serializer in this case
turansky
01/30/2021, 12:51 AM
contextual(Any::class, MyAnySerializer())
turansky
01/30/2021, 12:53 AM
Problem already was discussed in this channel. You can find exact solution in channel