Is there an "idiomatic" way to assign the default ...
# serialization
y
Is there an "idiomatic" way to assign the default value of a property when a
JsonDecodingException
is produced BECAUSE of that property? I can workaround it by using a custom serializer for that property but it's quite an overhead. e.g - for this data class
data class AA(val a: Int = 0)
and this json
{"a":"N/A"}
I will get this output
AA(a = 0)
despite it failed to decode it.
h
You get an IllegalFormatException or something? I think simply catching that exception is idiomatic enough. Or did I misunderstand the question?
y
well, If the class have more than a single property it becomes more complex to Identify and handle. I was thinking I am missing something as well as it seems a very desireble behaviour :) I guess (or hope) that in future releases we will be able to opt in to this behaviour through the Json configuration.
h
Ah yes, I misunderstood your original question. I thought you were already using a custom serializer and were wondering about how to implement it in there. Now that I have reread the question, I'll just agree with you on your second comment.
✌️ 1