Hi! I am using kotlinx.serialization and am runnin...
# getting-started
j
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:
Copy code
@Serializable
data class BaseResult<T>(val data: T, val foo: Int)

@Serializable
data class SomeData(val bar: String)

// Then when decoding incoming json I do:
val response = Json { ignoreUnknownKeys = true }
    .decodeFromString<BaseResult<SomeData>>(responseBody)
When doing this I get the following error:
Copy code
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... šŸ˜ž
a
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