Class PolymorphicConverter
Newtonsoft converter that resolves a discriminated union by reading its discriminator property (at any position in the object) and mapping the value to the concrete type registered via JsonSubTypeAttribute / JsonSubTypeNameAttribute. On write it emits the discriminator for the runtime type. It is attached to a hierarchy's root by the generator and inherited by every subtype.
Recursion is broken with the canonical per-thread CanRead /
CanWrite toggle: after resolving the concrete type, the converter
suppresses itself for exactly the one nested (de)serialization of that type,
so its own members are handled by the default contract while any polymorphic
fields WITHIN it (including recursive references back to the same union) are
still routed through the converter.
Inherited Members
Namespace: Pulumi.Cloud.Sdk
Assembly: Pulumi.Cloud.Sdk.dll
Syntax
public sealed class PolymorphicConverter : JsonConverter
Properties
View SourceCanRead
Gets a value indicating whether this Newtonsoft.Json.JsonConverter can read JSON.
Declaration
public override bool CanRead { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Overrides
CanWrite
Gets a value indicating whether this Newtonsoft.Json.JsonConverter can write JSON.
Declaration
public override bool CanWrite { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Overrides
Methods
View SourceCanConvert(Type)
Determines whether this instance can convert the specified object type.
Declaration
public override bool CanConvert(Type objectType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | objectType | Type of the object. |
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
View SourceReadJson(JsonReader, Type, object, JsonSerializer)
Reads the JSON representation of the object.
Declaration
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonReader | reader | The Newtonsoft.Json.JsonReader to read from. |
| Type | objectType | Type of the object. |
| object | existingValue | The existing value of object being read. |
| JsonSerializer | serializer | The calling serializer. |
Returns
| Type | Description |
|---|---|
| object | The object value. |
Overrides
View SourceWriteJson(JsonWriter, object, JsonSerializer)
Writes the JSON representation of the object.
Declaration
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonWriter | writer | The Newtonsoft.Json.JsonWriter to write to. |
| object | value | The value. |
| JsonSerializer | serializer | The calling serializer. |