@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
marstran
03/27/2020, 11:28 AM
You can use triple backticks ``` to format the code in a code block.
marstran
03/27/2020, 11:30 AM
Or mark the text and choose "Code block"
g
gabin
03/27/2020, 11:31 AM
ok, thx
gabin
03/27/2020, 12:17 PM
any help regarding the problem?
gabin
03/27/2020, 1:52 PM
@elizarov could you help please?
m
miqbaldc
03/28/2020, 11:42 AM
I think you need to annotate with
@Transient
or
@Optional
iinm cmiiw @gabin
e
elizarov
03/30/2020, 11:08 AM
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.