Table of Contents

Class JsonConverter<T>

Namespace
Nerdbank.Json
Assembly
Nerdbank.Json.dll

Base type for JSON converters that handle a specific .NET type.

public abstract class JsonConverter<T> : JsonConverter

Type Parameters

T

The .NET type handled by the converter.

Inheritance
JsonConverter<T>
Inherited Members

Methods

Read(ref JsonReader, SerializationContext)

Reads a value from JSON.

public abstract T? Read(ref JsonReader reader, SerializationContext context)

Parameters

reader JsonReader

The reader to consume the JSON value from.

context SerializationContext

Context for the deserialization operation.

Returns

T

The deserialized value.

ReadAsync(JsonAsyncReader, SerializationContext)

Reads a value from an asynchronous, incremental reader.

public virtual ValueTask<T?> ReadAsync(JsonAsyncReader reader, SerializationContext context)

Parameters

reader JsonAsyncReader

The asynchronous reader.

context SerializationContext

Context for the deserialization operation.

Returns

ValueTask<T>

A task whose result is the deserialized value.

Remarks

The default implementation buffers the next complete JSON value and delegates to Read(ref JsonReader, SerializationContext). Override this only when a value may be very large; read fragments and periodically await more data so memory stays bounded.

Write(ref JsonWriter, T?, SerializationContext)

Writes a value as JSON.

public abstract void Write(ref JsonWriter writer, T? value, SerializationContext context)

Parameters

writer JsonWriter

The writer to receive the JSON value.

value T

The value to write.

context SerializationContext

Context for the serialization operation.

WriteAsync(JsonAsyncWriter, T?, SerializationContext)

Writes a value as JSON to an asynchronous, incremental writer.

public virtual ValueTask WriteAsync(JsonAsyncWriter writer, T? value, SerializationContext context)

Parameters

writer JsonAsyncWriter

The asynchronous writer.

value T

The value to write.

context SerializationContext

Context for the serialization operation.

Returns

ValueTask

A task tracking the asynchronous write.

Remarks

The default implementation writes the whole value synchronously and then flushes the pipe if the buffer is large. Override this only when a value may be very large; write fragments and periodically call FlushIfAppropriateAsync(SerializationContext) to keep memory bounded.