Table of Contents

Interface IXpingSerializer

Namespace
Xping.Sdk.Core.Serialization
Assembly
Xping.Sdk.Core.dll

Defines the contract for serialization and deserialization operations in the Xping SDK. This interface provides a centralized way to serialize test execution data to JSON format and deserialize it back to strongly-typed objects.

public interface IXpingSerializer

Methods

DeserializeAsync<T>(Stream, CancellationToken)

Asynchronously deserializes a stream containing JSON to an object of the specified type. This method is useful for deserializing large objects or when working with streams.

Task<T?> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream containing the JSON to deserialize.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task<T>

A task representing the asynchronous operation, containing the deserialized object or null.

Type Parameters

T

The type to deserialize to.

Remarks

The stream is NOT disposed by this method. The caller retains ownership of the stream and is responsible for disposing it. The stream position is advanced as data is read. The stream remains open after deserialization completes.

Exceptions

ArgumentNullException

Thrown when stream is null.

JsonException

Thrown when the JSON is invalid or cannot be converted to the target type.

Deserialize<T>(ReadOnlySpan<byte>)

Deserializes a UTF-8 encoded JSON byte array to an object of the specified type.

T? Deserialize<T>(ReadOnlySpan<byte> utf8Json)

Parameters

utf8Json ReadOnlySpan<byte>

The UTF-8 encoded JSON byte array to deserialize.

Returns

T

The deserialized object, or null if the JSON represents a null value.

Type Parameters

T

The type to deserialize to.

Exceptions

JsonException

Thrown when the JSON is invalid or cannot be converted to the target type.

Deserialize<T>(string)

Deserializes a JSON string to an object of the specified type.

T? Deserialize<T>(string json)

Parameters

json string

The JSON string to deserialize.

Returns

T

The deserialized object, or null if the JSON represents a null value.

Type Parameters

T

The type to deserialize to.

Exceptions

ArgumentNullException

Thrown when json is null.

JsonException

Thrown when the JSON is invalid or cannot be converted to the target type.

SerializeAsync<T>(Stream, T, CancellationToken)

Asynchronously serializes an object to a stream in JSON format. This method is useful for serializing large objects or when working with streams.

Task SerializeAsync<T>(Stream stream, T value, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to write the JSON to.

value T

The object to serialize.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task

A task representing the asynchronous operation.

Type Parameters

T

The type of the object to serialize.

Remarks

The stream is NOT disposed by this method. The caller retains ownership of the stream and is responsible for disposing it. The stream position is advanced to the end of the written content, and the stream is flushed to ensure all data is written.

Exceptions

ArgumentNullException

Thrown when stream or value is null.

SerializeToUtf8Bytes<T>(T)

Serializes an object to a UTF-8 encoded byte array.

byte[] SerializeToUtf8Bytes<T>(T value)

Parameters

value T

The object to serialize.

Returns

byte[]

A UTF-8 encoded byte array containing the JSON representation.

Type Parameters

T

The type of the object to serialize.

Exceptions

ArgumentNullException

Thrown when value is null.

Serialize<T>(T)

Serializes an object to a JSON string.

string Serialize<T>(T value)

Parameters

value T

The object to serialize.

Returns

string

A JSON string representation of the object.

Type Parameters

T

The type of the object to serialize.

Exceptions

ArgumentNullException

Thrown when value is null.