Show / Hide Table of Contents

Struct JsonSerializable<T>

Represents a bridge between JSON serialization framework in .NET and ISerializable<TSelf> interface.

Implements
ISerializable<JsonSerializable<T>>
IDataTransferObject
ISupplier<T>
IFunctional
IEquatable<JsonSerializable<T>>
Inherited Members
object.GetType()
object.Equals(object, object)
object.ReferenceEquals(object, object)
Namespace: DotNext.Text.Json
Assembly: DotNext.IO.dll
Syntax
public struct JsonSerializable<T> : ISerializable<JsonSerializable<T>>, IDataTransferObject, ISupplier<T?>, IFunctional, IEquatable<JsonSerializable<T>> where T : IJsonSerializable<T>
Type Parameters
Name Description
T

JSON serializable type.

Fields

View Source

Value

Represents JSON serializable object.

Declaration
public required T? Value
Field Value
Type Description
T

Methods

View Source

DeserializeAsync<TReader>(TReader, CancellationToken)

Reads the UTF-8 encoded text representing a single JSON value. The input will be read to completion.

Declaration
public static ValueTask<T?> DeserializeAsync<TReader>(TReader reader, CancellationToken token = default) where TReader : IAsyncBinaryReader
Parameters
Type Name Description
TReader reader

The input containing UTF-8 encoded text.

CancellationToken token

The token which may be used to cancel the read operation.

Returns
Type Description
ValueTask<T>

A value deserialized from JSON.

Type Parameters
Name Description
TReader

The type of the reader.

View Source

Equals(JsonSerializable<T>)

Declaration
public readonly bool Equals(JsonSerializable<T> other)
Parameters
Type Name Description
JsonSerializable<T> other
Returns
Type Description
bool
View Source

Equals(object)

Declaration
public override readonly bool Equals(object obj)
Parameters
Type Name Description
object obj
Returns
Type Description
bool
Overrides
ValueType.Equals(object)
View Source

GetHashCode()

Declaration
public override readonly int GetHashCode()
Returns
Type Description
int
Overrides
ValueType.GetHashCode()
View Source

SerializeAsync<TWriter>(TWriter, T?, CancellationToken)

Writes one JSON value (including objects or arrays) to the provided writer.

Declaration
public static ValueTask SerializeAsync<TWriter>(TWriter writer, T? value, CancellationToken token) where TWriter : IAsyncBinaryWriter
Parameters
Type Name Description
TWriter writer

UTF-8 output to write to.

T value

The value to convert.

CancellationToken token

The token that can be used to cancel the write operation.

Returns
Type Description
ValueTask

A task that represents the asynchronous write operation.

Type Parameters
Name Description
TWriter

The type of the writer.

View Source

ToString()

Declaration
public override readonly string? ToString()
Returns
Type Description
string
Overrides
ValueType.ToString()
View Source

TransformAsync<TInput>(TInput, CancellationToken)

Converts an object to JSON-serializable data transfer object.

Declaration
public static ValueTask<T?> TransformAsync<TInput>(TInput input, CancellationToken token = default) where TInput : IDataTransferObject
Parameters
Type Name Description
TInput input

The object to transform.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<T>

Deserialized object.

Type Parameters
Name Description
TInput

The type of the object to transform.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

Operators

View Source

operator ==(JsonSerializable<T>, JsonSerializable<T>)

Declaration
public static bool operator ==(JsonSerializable<T> left, JsonSerializable<T> right)
Parameters
Type Name Description
JsonSerializable<T> left
JsonSerializable<T> right
Returns
Type Description
bool
View Source

operator !=(JsonSerializable<T>, JsonSerializable<T>)

Declaration
public static bool operator !=(JsonSerializable<T> left, JsonSerializable<T> right)
Parameters
Type Name Description
JsonSerializable<T> left
JsonSerializable<T> right
Returns
Type Description
bool

Explicit Interface Implementations

View Source

ReadFromAsync<TReader>(TReader, CancellationToken)

Decodes the object of type TSelf from its binary representation.

Declaration
static ValueTask<JsonSerializable<T>> ReadFromAsync<TReader>(TReader reader, CancellationToken token = default) where TReader : IAsyncBinaryReader
Parameters
Type Name Description
TReader reader

The reader.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<JsonSerializable<T>>

The decoded object.

Type Parameters
Name Description
TReader

The type of the reader.

Exceptions
Type Condition
OperationCanceledException

The operation has been canceled.

Implements

ISerializable<TSelf>
IDataTransferObject
ISupplier<TResult>
IFunctional
IEquatable<T>

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
DataTransferObject.ToByteArrayAsync<TObject>(TObject, MemoryAllocator<byte>?, CancellationToken)
DataTransferObject.ToMemoryAsync<TObject>(TObject, MemoryAllocator<byte>?, CancellationToken)
DataTransferObject.ToStringAsync<TObject>(TObject, Encoding, MemoryAllocator<byte>?, CancellationToken)
DataTransferObject.TransformAsync<TResult, TObject>(TObject, Func<IAsyncBinaryReader, CancellationToken, ValueTask<TResult>>, CancellationToken)
DataTransferObject.WriteToAsync<TObject>(TObject, IBufferWriter<byte>, CancellationToken)
DataTransferObject.WriteToAsync<TObject>(TObject, PipeWriter, long, CancellationToken)
DataTransferObject.WriteToAsync<TObject>(TObject, Stream, int, CancellationToken)
DataTransferObject.WriteToAsync<TObject>(TObject, Stream, Memory<byte>, CancellationToken)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾