Open amir1376 opened 3 months ago
We don't have embedded functionality for this. The closest one is coerceInputValue
, but it is for enums only. You can look at the json transformations (https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/json.md#json-transformations) to achieve result that you want.
But If I have to write custom serializer or transformer, I have to write it for all of my nested serializable classes
is that right?
could I do this globaly (or at least on my parent class only) some how?
Generally, yes, each class has its own serializer. However, you can move some common parts to a serializers' common ancestor
Just make sure that each one has a different name (serialname of the typeis used as unique identifier for caching etc.)
Let's suppose I have this class
I have serialized this class to a file which the result is
now some folk comes and change the json file content to this
now when I try to deserialize my
Settings
class it will throw an exceptionIs there any way when a key can't be deserialized use a default value and make the deserialization success ?
I need this result
this is a simple example it could be very nested