Table of Contents

Class SyntaxNodeSubtypeJsonConverter<T>

Namespace
RDCore.SDK.Model.AST.Abstract
Assembly
RDCore.SDK.dll

Bridges polymorphic (de)serialization for a property or collection element declared as a narrower abstract SyntaxNode subtype (e.g. ExpressionNode) rather than SyntaxNode itself.

public sealed class SyntaxNodeSubtypeJsonConverter<T> : JsonConverter<T> where T : SyntaxNode

Type Parameters

T
Inheritance
SyntaxNodeSubtypeJsonConverter<T>
Inherited Members

Remarks

[JsonPolymorphic]/[JsonDerivedType] is declared once, on SyntaxNode. System.Text.Json resolves polymorphism from the property's own declared type, and does not apply an ancestor's attributes to a narrower abstract type that carries none of its own — so a property like IfBlockStatementNode.ConditionExpression : ExpressionNode would otherwise throw NotSupportedException ("Deserialization of interface or abstract types is not supported") the moment it round-trips through JSON, since ExpressionNode itself carries no polymorphism attributes. Delegating through SyntaxNode reuses the one declaration instead of repeating the whole derived-type list on every abstract subtype.

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to type T.

public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Parameters

reader Utf8JsonReader

The reader.

typeToConvert Type

The type to convert.

options JsonSerializerOptions

An object that specifies serialization options to use.

Returns

T

The converted value.

Write(Utf8JsonWriter, T, JsonSerializerOptions)

Writes a specified value as JSON.

public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The writer to write to.

value T

The value to convert to JSON.

options JsonSerializerOptions

An object that specifies serialization options to use.