Table of Contents

Class JsonUnionConfiguration

Namespace
Nerdbank.Json
Assembly
Nerdbank.Json.dll

An immutable, serializer-scoped set of runtime overrides for polymorphic union (sub-type) serialization.

public sealed class JsonUnionConfiguration
Inheritance
JsonUnionConfiguration
Inherited Members

Remarks

By default, unions are described entirely by shape-generated metadata and use the two-element [discriminator, payload] representation. This configuration lets a caller add a union for a base type, replace or extend the generated cases, or disable union handling, using explicitly supplied ITypeShape<T> instances so the feature remains NativeAOT-safe.

Instances are immutable; every method returns a new configuration. Reusing the same instance across serializers preserves converter-cache identity, while assigning a different instance rebuilds the cache.

Properties

Default

Gets the empty configuration that applies no runtime overrides.

public static JsonUnionConfiguration Default { get; }

Property Value

JsonUnionConfiguration

Methods

WithUnion<TBase>(JsonUnion<TBase>)

Returns a configuration that applies the specified union definition to TBase.

public JsonUnionConfiguration WithUnion<TBase>(JsonUnion<TBase> union)

Parameters

union JsonUnion<TBase>

The union definition to apply.

Returns

JsonUnionConfiguration

A new configuration.

Type Parameters

TBase

The base type whose union handling is overridden.

WithoutUnion<TBase>()

Returns a configuration that disables union handling for TBase, serializing values as the plain base type without a discriminator envelope.

public JsonUnionConfiguration WithoutUnion<TBase>()

Returns

JsonUnionConfiguration

A new configuration.

Type Parameters

TBase

The base type whose union handling is disabled.