Koya Sivaji
08/04/2020, 3:42 PM@Serializable
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
"attributes":{
"home":null,
"room":"null",
"announcement":null,
"push_notification_enabled":null
}
what is expected is
"attributes":{}
Note: serialize() is an extension function as below
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 null
fields from data class. Anyone has idea of how to do thatokarm
08/04/2020, 7:56 PMJustin Shapiro
08/05/2020, 12:45 AM