Class UnionJsonConverter<T>
Abstract base class for JSON converters that handle polymorphic types based on a type discriminator field.
Inherited Members
Namespace: Glitch9.IO.Json
Assembly: Glitch9.IO.dll
Syntax
public abstract class UnionJsonConverter<T> : JsonConverter<T>
Type Parameters
| Name | Description |
|---|---|
| T | The base type to convert. |
Properties
| Edit this page View SourceDiscriminatorFieldName
Declaration
protected virtual string DiscriminatorFieldName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
| Edit this page View SourceCreateInstance(string)
Creates an instance of the appropriate derived type based on the type discriminator value.
Declaration
protected abstract T CreateInstance(string type)
Parameters
| Type | Name | Description |
|---|---|---|
| string | type | The type discriminator value from the JSON. |
Returns
| Type | Description |
|---|---|
| T | An instance of the derived type, or null if the type is not recognized. |
GetDiscriminatorValue(JObject)
Gets the name of the JSON field used as the type discriminator.
Declaration
protected virtual string GetDiscriminatorValue(JObject jo)
Parameters
| Type | Name | Description |
|---|---|---|
| JObject | jo |
Returns
| Type | Description |
|---|---|
| string | The field name (default: "type"). |
ReadJson(JsonReader, Type, T, bool, JsonSerializer)
Reads the JSON representation of the object.
Declaration
public override T ReadJson(JsonReader reader, Type objectType, T existingValue, bool hasExistingValue, JsonSerializer serializer)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonReader | reader | The Newtonsoft.Json.JsonReader to read from. |
| Type | objectType | Type of the object. |
| T | existingValue | The existing value of object being read. If there is no existing value then |
| bool | hasExistingValue | The existing value has a value. |
| JsonSerializer | serializer | The calling serializer. |
Returns
| Type | Description |
|---|---|
| T | The object value. |
Overrides
| Edit this page View SourceResolveDiscriminatorValue(T)
Declaration
protected virtual string ResolveDiscriminatorValue(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value |
Returns
| Type | Description |
|---|---|
| string |
WriteJson(JsonWriter, T, JsonSerializer)
Writes the JSON representation of the object.
Declaration
public override void WriteJson(JsonWriter writer, T value, JsonSerializer serializer)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonWriter | writer | The Newtonsoft.Json.JsonWriter to write to. |
| T | value | The value. |
| JsonSerializer | serializer | The calling serializer. |