Table of Contents

Class JsonSerializer<T>

Namespace
Ecng.Serialization
Assembly
Ecng.Serialization.dll

Provides JSON serialization and deserialization for a given type.

public class JsonSerializer<T> : Serializer<T>, ISerializer<T>, ISerializer, IJsonSerializer

Type Parameters

T

The type of the graph to serialize and deserialize.

Inheritance
JsonSerializer<T>
Implements
Inherited Members
Extension Methods

Constructors

JsonSerializer()

public JsonSerializer()

Properties

BufferSize

Gets or sets the buffer size used during serialization and deserialization.

public int BufferSize { get; set; }

Property Value

int

Encoding

Gets or sets the text encoding used for serialization. Defaults to UTF8.

public Encoding Encoding { get; set; }

Property Value

Encoding

EncryptedAsByteArray

Gets or sets a value indicating whether encrypted values are handled as byte arrays.

public bool EncryptedAsByteArray { get; set; }

Property Value

bool

EnumAsString

Gets or sets a value indicating whether enums should be serialized as strings.

public bool EnumAsString { get; set; }

Property Value

bool

FileExtension

Gets the file extension associated with the JSON serializer.

public override string FileExtension { get; }

Property Value

string

FillMode

Gets or sets a value indicating whether the fill mode is enabled.

public bool FillMode { get; set; }

Property Value

bool

Indent

Gets or sets a value indicating whether the JSON output should be indented.

public bool Indent { get; set; }

Property Value

bool

NullValueHandling

Gets or sets the null value handling option for JSON serialization.

public NullValueHandling NullValueHandling { get; set; }

Property Value

NullValueHandling

Methods

CreateDefault()

Creates a default instance of the JSON serializer with preconfigured settings.

public static JsonSerializer<T> CreateDefault()

Returns

JsonSerializer<T>

A default JsonSerializer<T> instance.

DeserializeAsync(Stream, CancellationToken)

Asynchronously deserializes an object graph from the provided JSON stream.

public override ValueTask<T> DeserializeAsync(Stream stream, CancellationToken cancellationToken)

Parameters

stream Stream

The stream from which the object graph is deserialized.

cancellationToken CancellationToken

A token that can be used to cancel the deserialization operation.

Returns

ValueTask<T>

A task representing the asynchronous deserialization operation. The task result contains the deserialized object graph.

SerializeAsync(T, Stream, CancellationToken)

Asynchronously serializes the specified object graph to the provided stream as JSON.

public override ValueTask SerializeAsync(T graph, Stream stream, CancellationToken cancellationToken)

Parameters

graph T

The object graph to serialize.

stream Stream

The stream to which the graph is serialized.

cancellationToken CancellationToken

A token that can be used to cancel the serialization operation.

Returns

ValueTask

A task representing the asynchronous serialization operation.