Q: I have a serializable data class Foo which has ...
# serialization
m
Q: I have a serializable data class Foo which has two properties a, b
Copy code
@Serializable
data class Foo(
    val a: String,
    val b: List<String>
)
I'd like to handle read/write asymmetrically in this case (using JSON): - For read I'd like to read both a and b properties from json string - For write however I'd like to serialize only b to json string I've tried the Mapper to convert this to a map remove the unwanted key, but then I could not find a way to serialize the Map<String, Any> What do you think would be the best solution for this case? Something like @Transient(In|Out|InOut) would be great 🙂
j
Just curious, why wont @Optional with
val a:String? = null
be enough?
m
because it should not be null I just don't want to write it
Foo itself need all of the properties set 😞
j
Seems awfully weird. The basis for serialization is that the serialized format is going to match whatever your model holds. It still has to zero pad the bytes ending up in the output even though its going to be empty