Hi, is it possible to enforce required/optional fi...
# ktor
b
Hi, is it possible to enforce required/optional fields in JSON serialization? It seems that kotlinx.serialization does the job of enforcing that fields should be required if no defaults are provided, but I was wondering if I can make some optional by saying it’s nullable with e.g.
String?
or
Optional<String>
?
s
AFAIR,
kotlinx.serialization
can use default values from the constructor. Have you checked?
b
yes, but that’s not really a same thing. I would have to check for each value is it default. And it would become bloated with complex classes
s
What do you want to do then? Aren't you requesting for something like
@Serializable class MyData(val optionalString: String? = null)
?