Class JsonConverter
- Namespace
- Nerdbank.Json
- Assembly
- Nerdbank.Json.dll
Base type for JSON converters.
public abstract class JsonConverter
- Inheritance
-
JsonConverter
- Derived
- Inherited Members
Properties
PreferAsyncSerialization
Gets a value indicating whether this converter's asynchronous methods should be preferred over its synchronous methods when a graph is being (de)serialized asynchronously.
public virtual bool PreferAsyncSerialization { get; }
Property Value
Remarks
The default is false, which means the default asynchronous methods buffer a whole value and delegate to the synchronous methods. Converters that may (de)serialize very large values should override the asynchronous methods, set this to true, and stream fragments so that memory use stays bounded.
Methods
GetJsonSchema(JsonSchemaContext, ITypeShape)
Produces a JSON Schema fragment that describes how this converter represents its value, or null if this converter cannot describe its representation.
public virtual JsonObject? GetJsonSchema(JsonSchemaContext context, ITypeShape typeShape)
Parameters
contextJsonSchemaContextThe schema-generation context, which resolves nested schemas and shared definitions.
typeShapeITypeShapeThe shape of the type this converter handles.
Returns
- JsonObject
A schema fragment, or null to indicate the representation is undocumented. When null is returned, the exporter emits a permissive schema annotated with a conspicuous comment rather than pretending to know the representation.
ReadObject(ref JsonReader, SerializationContext)
Reads an untyped value.
public abstract object? ReadObject(ref JsonReader reader, SerializationContext context)
Parameters
readerJsonReaderThe source reader.
contextSerializationContextThe operation context.
Returns
- object
The deserialized value.
ReadObjectAsync(JsonAsyncReader, SerializationContext)
Reads an untyped value asynchronously.
public abstract ValueTask<object?> ReadObjectAsync(JsonAsyncReader reader, SerializationContext context)
Parameters
readerJsonAsyncReaderThe source reader.
contextSerializationContextThe operation context.
Returns
SkipToIndexValue(ref JsonReader, object?, SerializationContext)
Skips to the value at a logical array index or dictionary key.
public virtual bool SkipToIndexValue(ref JsonReader reader, object? index, SerializationContext context)
Parameters
readerJsonReaderThe reader positioned at this converter's value.
indexobjectThe array index or dictionary key.
contextSerializationContextThe serialization context.
Returns
- bool
Whether the value was found, with the reader ready to read it.
SkipToIndexValueAsync(JsonAsyncReader, object?, SerializationContext)
Asynchronously skips to a logical array index or dictionary key.
public virtual ValueTask<bool> SkipToIndexValueAsync(JsonAsyncReader reader, object? index, SerializationContext context)
Parameters
readerJsonAsyncReaderThe asynchronous reader.
indexobjectThe array index or dictionary key.
contextSerializationContextThe serialization context.
Returns
Remarks
Use the reader's structural methods to enter containers so envelope draining can account for them.
SkipToPropertyValue(ref JsonReader, IPropertyShape, SerializationContext)
Skips to the value of a logical property in this converter's representation.
public virtual bool SkipToPropertyValue(ref JsonReader reader, IPropertyShape propertyShape, SerializationContext context)
Parameters
readerJsonReaderThe reader positioned at this converter's value.
propertyShapeIPropertyShapeThe logical property to select.
contextSerializationContextThe serialization context.
Returns
- bool
Whether the property was found, with the reader ready to read its value.
SkipToPropertyValueAsync(JsonAsyncReader, IPropertyShape, SerializationContext)
Asynchronously skips to the value of a logical property without buffering its enclosing value.
public virtual ValueTask<bool> SkipToPropertyValueAsync(JsonAsyncReader reader, IPropertyShape propertyShape, SerializationContext context)
Parameters
readerJsonAsyncReaderThe asynchronous reader.
propertyShapeIPropertyShapeThe logical property to select.
contextSerializationContextThe serialization context.
Returns
Remarks
Use the reader's structural methods to enter containers so envelope draining can account for them.
WriteObject(ref JsonWriter, object?, SerializationContext)
Writes an untyped value.
public abstract void WriteObject(ref JsonWriter writer, object? value, SerializationContext context)
Parameters
writerJsonWriterThe destination writer.
valueobjectThe value to write.
contextSerializationContextThe operation context.
WriteObjectAsync(JsonAsyncWriter, object?, SerializationContext)
Writes an untyped value asynchronously.
public abstract ValueTask WriteObjectAsync(JsonAsyncWriter writer, object? value, SerializationContext context)
Parameters
writerJsonAsyncWriterThe destination writer.
valueobjectThe value to write.
contextSerializationContextThe operation context.
Returns
- ValueTask
A task tracking the write.