ta-json icon indicating copy to clipboard operation
ta-json copied to clipboard

What are the requirements for "JsonDiscriminatorProperty" and "JsonDiscriminatorValue"?

Open runeksvendsen opened this issue 6 years ago • 0 comments

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:

  1. 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?
  2. Do all instances need a property that is set to this value?

runeksvendsen avatar Apr 15 '19 12:04 runeksvendsen