Skip to content

SubjectIdentifierJsonConverter Class

Reads and writes a SubjectIdentifier polymorphically, choosing the concrete subtype by the "format" member that RFC 9493 Section 3 requires every Subject Identifier to carry.

C#
public sealed class SubjectIdentifierJsonConverter : System.Text.Json.Serialization.JsonConverter<Abblix.SecurityEvents.Subjects.SubjectIdentifier>

Inheritance System.ObjectSystem.Text.Json.Serialization.JsonConverterSystem.Text.Json.Serialization.JsonConverter<SubjectIdentifier> → SubjectIdentifierJsonConverter

Remarks

The converter is attached to SubjectIdentifier itself, so it is reached whenever the declared type is the abstract base - the nested identifiers of an AliasesSubject among them - and is not reached when the declared type is already a concrete subtype. That asymmetry is what lets Write(Utf8JsonWriter, SubjectIdentifier, JsonSerializerOptions) hand the value straight back to the serializer under its runtime type without re-entering this converter.

A format outside the built-in vocabulary is supported by deriving from SubjectIdentifier and naming the subtype in the custom-formats map of SubjectIdentifierJsonConverter(IReadOnlyDictionary<string,Type>), then placing the resulting converter in the serializer options. Registration happens once, when the converter is built, so the map cannot change under a reader mid-flight.

Constructors

SubjectIdentifierJsonConverter() Constructor

Creates a converter that understands the built-in vocabulary: the formats of the IANA registry (RFC 9493 Section 8.1.2) and the SSF 1.0 extensions (Sections 3.3, 3.5).

C#
public SubjectIdentifierJsonConverter();

SubjectIdentifierJsonConverter(IReadOnlyDictionary<string,Type>) Constructor

Creates a converter that understands the built-in vocabulary plus the formats given.

C#
public SubjectIdentifierJsonConverter(System.Collections.Generic.IReadOnlyDictionary<string,System.Type>? customFormats);

Parameters

customFormats System.Collections.Generic.IReadOnlyDictionary<System.String,System.Type>

Format names mapped to the concrete SubjectIdentifier subtype that models them. A name from the built-in vocabulary cannot be redefined here: those formats are the shared vocabulary of their specifications, and quietly rebinding one would make two parties disagree about a document both consider valid.

Exceptions

System.ArgumentException
A name is null or empty, collides with the built-in vocabulary, or is mapped to a type that is not a concrete subclass of SubjectIdentifier.

Methods

SubjectIdentifierJsonConverter.CanConvert(Type) Method

Claims exactly the abstract base type and never a concrete subtype.

C#
public override bool CanConvert(System.Type typeToConvert);

Parameters

typeToConvert System.Type

Returns

System.Boolean

Remarks

Both Read(Utf8JsonReader, Type, JsonSerializerOptions) and Write(Utf8JsonWriter, SubjectIdentifier, JsonSerializerOptions) re-enter the serializer under the concrete subtype, and they terminate only because that request is NOT routed back here. The base implementation currently answers with exact type equality, which provides that guarantee, but the guarantee is this converter's termination condition, so it is stated here rather than inherited from behaviour that lives only in convention.

SubjectIdentifierJsonConverter.Read(Utf8JsonReader, Type, JsonSerializerOptions) Method

Reads a Subject Identifier, dispatching on its "format" member to the subtype that models that Identifier Format.

C#
public override Abblix.SecurityEvents.Subjects.SubjectIdentifier? Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options);

Parameters

reader System.Text.Json.Utf8JsonReader
typeToConvert System.Type
options System.Text.Json.JsonSerializerOptions

Returns

SubjectIdentifier

Exceptions

System.Text.Json.JsonException
The value is not a JSON object, carries no usable "format" member, names a format this converter has not been told about, or holds members its Identifier Format does not permit. The subtype constructors enforce the member rules and throw System.ArgumentException; this boundary translates that into the exception type callers of a deserializer guard against, so untrusted input fails with one exception type however it is malformed.

SubjectIdentifierJsonConverter.Write(Utf8JsonWriter, SubjectIdentifier, JsonSerializerOptions) Method

Writes a Subject Identifier in the shape its own Identifier Format defines, "format" member included.

C#
public override void Write(System.Text.Json.Utf8JsonWriter writer, Abblix.SecurityEvents.Subjects.SubjectIdentifier value, System.Text.Json.JsonSerializerOptions options);

Parameters

writer System.Text.Json.Utf8JsonWriter
value SubjectIdentifier

options System.Text.Json.JsonSerializerOptions