Hello guys. I’m looking for a workaround for an is...
# serialization
g
Hello guys. I’m looking for a workaround for an issue https://github.com/Kotlin/kotlinx.serialization/issues/195 Lets say I have a class
Copy code
@Serializable
data class MyUser(
    val fullName: String,
    val middleName: String? = null,
    val age: Int = 42
)
I want to achieve the result when following object
MyUser("John Doe")
will lead to json:
Copy code
{"fullName": "John Doe", age=42}
From what I understand
Json(encodeDefaults = false)
will disable adding default age. Please give an advice
m
You can use triple backticks ``` to format the code in a code block.
Or mark the text and choose "Code block"
g
ok, thx
any help regarding the problem?
@elizarov could you help please?
m
I think you need to annotate with
@Transient
or
@Optional
iinm cmiiw @gabin
e
Out-of-the-box you either have all defaults or none of them. To customize it, you’ll have to write your own serializer for this class or your own JSON format that whould treat nulls in some special way.
👍 1