Jonathan Olsson

03/25/2021, 7:57 AM
Hi! I am using kotlinx.serialization and am running into some issues with regards to generic values in data classes. I have roughly the following:
data class BaseResult<T>(val data: T, val foo: Int)

data class SomeData(val bar: String)

// Then when decoding incoming json I do:
val response = Json { ignoreUnknownKeys = true }
When doing this I get the following error:
Serializer for class 'SomeData' is not found.
kotlinx.serialization.SerializationException: Serializer for class 'SomeData' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
Hmm. Actually this was due to gradle (i.e. me) not properly applying the serialization plugin. The gradle pluginManagement is very, very confusing and subtle to me... 😞


03/25/2021, 11:49 AM
you usually don’t need pluginManagement{}, just put the plugin into a plugins{} block at the top of the build file. For multi-module projects, only put the version number in the root build file (with “apply false” if the root project has no code)
👍 1