Hi, I have a strange Kotlin serialisation issue in...
# android
t
Hi, I have a strange Kotlin serialisation issue in my current Android application
Part of my API Request resembles this data model, which I have populated with default values
Copy code
@Serializable
data class RequestOptionalInput(

    @SerialName("USER_AGENT")
    val userAgent: String = "",

    @SerialName("WEB_SERVER")
    val webServer: String = "",

    @SerialName("REFERRER")
    val referrer: String = "0.0.0.0",

    @SerialName("ROUTE")
    val route: String = "/",

    @SerialName("ANALYTICS_ID")
    val analyticsId: String = "",

    @SerialName("DOMAIN_TOKEN")
    val domainToken: String = "",

    @SerialName("DOMAIN_NAME")
    val domainName: String = ""
)
However when I perform
Copy code
json.encodeToString(request)
on the entire request object all my default values are completly missing, the only way I can get the "default" values to appear is to "manually" set them in the constructor. Is there any approach I can use that will allo wme to use the default values? instaed of having to always code them passed in the data class constructor?
h
must have to call constructor
e
Copy code
val json = Json { encodeDefaults = true }
t
Nice I tried searching for that type of config and failed 🤦‍♂️ thanks for taking the time to assist me 😄