Megan Teahan
01/29/2021, 4:43 PMAny
in a nested Map and I'm using the @contextual method defined in this post:
@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
kotlinx.serialization.SerializationException: Serializer for class 'Any' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
Am I missing something?turansky
01/29/2021, 11:42 PM@Contextual
require context for Any
type (missed in json
constant)Megan Teahan
01/30/2021, 12:46 AMAny
doesn't have its own serializer so I can't do something like contextual(Any.serializer())
.turansky
01/30/2021, 12:50 AMturansky
01/30/2021, 12:51 AMcontextual(Any::class, MyAnySerializer())
turansky
01/30/2021, 12:53 AMturansky
01/30/2021, 12:55 AM