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
TThe .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
readerJsonReaderThe reader to consume the JSON value from.
contextSerializationContextContext 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
readerJsonAsyncReaderThe asynchronous reader.
contextSerializationContextContext 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
writerJsonWriterThe writer to receive the JSON value.
valueTThe value to write.
contextSerializationContextContext 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
writerJsonAsyncWriterThe asynchronous writer.
valueTThe value to write.
contextSerializationContextContext 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.