Show / Hide Table of Contents

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.

Inheritance
object
JsonConverter
PolymorphicConverter
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Pulumi.Cloud.Sdk
Assembly: Pulumi.Cloud.Sdk.dll
Syntax
public sealed class PolymorphicConverter : JsonConverter

Properties

View Source

CanRead

Gets a value indicating whether this Newtonsoft.Json.JsonConverter can read JSON.

Declaration
public override bool CanRead { get; }
Property Value
Type Description
bool

true if this Newtonsoft.Json.JsonConverter can read JSON; otherwise, false.

Overrides
Newtonsoft.Json.JsonConverter.CanRead
View Source

CanWrite

Gets a value indicating whether this Newtonsoft.Json.JsonConverter can write JSON.

Declaration
public override bool CanWrite { get; }
Property Value
Type Description
bool

true if this Newtonsoft.Json.JsonConverter can write JSON; otherwise, false.

Overrides
Newtonsoft.Json.JsonConverter.CanWrite

Methods

View Source

CanConvert(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

true if this instance can convert the specified object type; otherwise, false.

Overrides
JsonConverter.CanConvert(Type)
View Source

ReadJson(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
JsonConverter.ReadJson(JsonReader, Type, object, JsonSerializer)
View Source

WriteJson(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.

Overrides
JsonConverter.WriteJson(JsonWriter, object, JsonSerializer)

Version 2026.10.9

  • View Source
Back to top Copyright 2016-2026, Pulumi Corporation.