Skip to content

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

@runeksvendsen

Description

@runeksvendsen

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions