Earlier quoted context omitted.
> Also lack of inheritance support. (For example I want a way to specify that my json object should be deserialized as Dog not as Animal.) Use Typescript, then so long as it barks, you can treat it like a dog! And if it knows how to bark and meow, you can treat it as a dog or a cat at your leisure. :-D
The issue is when JSON has to be parsed on the server using Java/C#. How do you know whether to parse it as a Dog or as a Cat (both of which inherits from Animal)? Here's Microsoft's workaround: https://devblogs.microsoft.com/dotnet/system-text-json-in-do...
"properties": {
"cat": {
"$ref": "#/$defs/catType"
}
"dog": {
"$ref": "#/$defs/dogType"
}
},
"oneOf": [
{
"required": ["cat"]
},
{
"required": ["dog"]
},
]
Usage would then look like: {
"dog": {
"name": "Charlie"
}
}
At least it's explicit and can be easily checked for validity.[1]: https://json-schema.org/understanding-json-schema/reference/...
[2]: https://json-schema.org/understanding-json-schema/reference/...