I would like to serialize and deserialize multiple instances of a common interface. To do this, the README says I should use JsonDiscriminatorProperty
and JsonDiscriminatorValue
. However, it doesn't say what these actually do, or what the requirements are for using these decorators, so I will ask here:
Is it required that my superclass/interface has a property that describes the subclass type? For example, the Animal
type in the example has a type:AnimalType
field (pointed to by the JsonDiscriminatorProperty
decorator). Is this required for (de)serialization to work?
In other words:
- Do I have to create a distinct value (e.g. via an enum) for all the subtypes of the interface/superclass I want to serialize?
- Do all instances need a property that is set to this value?