Share via


DiscriminatedTypeJsonConverter<TBase> Class

Definition

Allows type hierarchies to be de/serialized by automatically applying, and then reading, an additional json property with a type discriminator value. In addition to the Newtonsoft.Json.JsonConverterAttribute, the base type should also be decorated with one or more TypeDiscriminatorAttribute.

generic <typename TBase>
 where TBase : classpublic ref class DiscriminatedTypeJsonConverter : Newtonsoft::Json::JsonConverter<TBase>
public class DiscriminatedTypeJsonConverter<TBase> : Newtonsoft.Json.JsonConverter<TBase> where TBase : class
type DiscriminatedTypeJsonConverter<'Base (requires 'Base : null)> = class
    inherit JsonConverter<'Base (requires 'Base : null)>
Public Class DiscriminatedTypeJsonConverter(Of TBase)
Inherits JsonConverter(Of TBase)

Type Parameters

TBase

The base type of the hierarchy.

Inheritance
Newtonsoft.Json.JsonConverter<TBase>
DiscriminatedTypeJsonConverter<TBase>

Remarks

All subtypes in the type hierarchy must support initialization via a constructor. This converter will not work with subtypes that only have default constructors and writable properties.

Constructors

DiscriminatedTypeJsonConverter<TBase>()

Initializes a new instance of the DiscriminatedTypeJsonConverter<TBase> class, using '$rpctype' for the name of the property that stores the type discriminator value.

Failures in type discrimation will throw.

TBase must be a concrete type. To use an abstract type for TBase use either the overload DiscriminatedTypeJsonConverter<TBase>(Type) or DiscriminatedTypeJsonConverter<TBase>(Type, String).

DiscriminatedTypeJsonConverter<TBase>(Boolean)

Initializes a new instance of the DiscriminatedTypeJsonConverter<TBase> class, using '$rpctype' for the name of the property that stores the type discriminator value.

DiscriminatedTypeJsonConverter<TBase>(Boolean, String)

Initializes a new instance of the DiscriminatedTypeJsonConverter<TBase> class, using '$rpctype' for the name of the property that stores the type discriminator value.

DiscriminatedTypeJsonConverter<TBase>(String)

Initializes a new instance of the DiscriminatedTypeJsonConverter<TBase> class, using TBase as the fallback type.

DiscriminatedTypeJsonConverter<TBase>(Type)

Initializes a new instance of the DiscriminatedTypeJsonConverter<TBase> class, using '$rpctype' for the name of the property that stores the type discriminator value.

DiscriminatedTypeJsonConverter<TBase>(Type, String)

Initializes a new instance of the DiscriminatedTypeJsonConverter<TBase> class.

Methods

ReadJson(JsonReader, Type, TBase, Boolean, JsonSerializer) Newtonsoft.Json.JsonConverter`1.ReadJson(Newtonsoft.Json.JsonReader,System.Type,`0,System.Boolean,Newtonsoft.Json.JsonSerializer)
WriteJson(JsonWriter, TBase, JsonSerializer) Newtonsoft.Json.JsonConverter`1.WriteJson(Newtonsoft.Json.JsonWriter,`0,Newtonsoft.Json.JsonSerializer)

Applies to