https://kotlinlang.org logo
#serialization
Title
# serialization
r

ribesg

03/07/2023, 6:44 AM
Encountered a regression issue while upgrading my iOS project (Kotlin 1.7->1.8, Gradle 7->8, serialization 1.4->1.5):
Copy code
kotlinx.serialization.SerializationException: Serializer for class 'Any' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
I had this little bit of code to help set the json body with the appropriate content type every time:
Copy code
fun HttpRequestBuilder.setJsonBody(value: Any) {
    contentType(Application.Json)
    setBody(value)
}
Worked perfectly fine, but seems like it no longer does. Maybe it's a good thing, I don't know. Looks like changing it to be inline with reified generic type fixed my issue:
Copy code
inline fun <reified T : Any> HttpRequestBuilder.setJsonBody(value: T) {
    contentType(Application.Json)
    setBody(value)
}
12 Views