3 ms·
> However, in statically typed languages, people wanted to deserialize data into static types that don't support the concept of "undefined." This was the beginn
by mixedCase 4y ago
> However, in statically typed languages, people wanted to deserialize data into static types that don't support the concept of "undefined." This was the beginning of the end, because deserializing into a static type is actually a bug for an API that has an evolving schema
No, that's just a bug in your type.
data FieldPatch a
= Value a -- A value unmarshable to type `a` was given, apply patch
| SetToNull -- null was given, apply and patch to null
| Undefined -- field was not set, do not patch
| UnexpectedValue RawJSON -- optional, allows manual handling of unexpected types
You can do this in things like Java too with interfaces if you can tolerate openness, or if you want closed types like in the example, through the visitor pattern.
- brabel 4y ago> You can do this in things like Java too with interfaces if you can tolerate openness Java supports sealed interfaces now, so this is not true anymore.