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
TThe type of the graph to serialize and deserialize.
- Inheritance
-
Serializer<T>JsonSerializer<T>
- Implements
-
ISerializer<T>
- 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
Encoding
Gets or sets the text encoding used for serialization. Defaults to UTF8.
public Encoding Encoding { get; set; }
Property Value
EncryptedAsByteArray
Gets or sets a value indicating whether encrypted values are handled as byte arrays.
public bool EncryptedAsByteArray { get; set; }
Property Value
EnumAsString
Gets or sets a value indicating whether enums should be serialized as strings.
public bool EnumAsString { get; set; }
Property Value
FileExtension
Gets the file extension associated with the JSON serializer.
public override string FileExtension { get; }
Property Value
FillMode
Gets or sets a value indicating whether the fill mode is enabled.
public bool FillMode { get; set; }
Property Value
Indent
Gets or sets a value indicating whether the JSON output should be indented.
public bool Indent { get; set; }
Property Value
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
streamStreamThe stream from which the object graph is deserialized.
cancellationTokenCancellationTokenA 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
graphTThe object graph to serialize.
streamStreamThe stream to which the graph is serialized.
cancellationTokenCancellationTokenA token that can be used to cancel the serialization operation.
Returns
- ValueTask
A task representing the asynchronous serialization operation.