I am using Kotlinx serializer for serializing/des...
# android
I am using Kotlinx serializer for serializing/deserializing of data classes with retrofit. I need to skip the null values from serialization, but I couldn’t find the way to do that here is my data class
Copy code
data class Attributes(
    val home: String? = null,
    val room: String? = null,
    val announcement: Int? = null,
    val push_notification_enabled: Int? = null
when I called Attributes().serialize() , the resulting json as below
Copy code
what is expected is
Copy code
Note: serialize() is an extension function as below
Copy code
inline fun <reified T: Any> T.serialize(): String {
    return Json.stringify(T::class.serializer(), this)
Basically I want to exclude all null params from serialization. I tried with by setting
JsonConfiguration( encodeDefaults = false)
, but still resulting json includes
fields from data class. Anyone has idea of how to do that
you want JsonTransformingSerializer to drop the nulls after you serialize. https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/json_transformations.md