Table of Contents

Class StravaSerializer

Namespace
Tudormobile.Strava
Assembly
Tudormobile.Strava.dll

Serializer for Tudormobile.Strava model objects.

public static class StravaSerializer
Inheritance
StravaSerializer
Inherited Members

Remarks

The serializer uses the JsonSerializer class to convert between JSON and model objects. Serialization options include snake case (lower) property names and case insensitivity. Some specific model objects may include custom serialization. Strava API dates and times are converted to DateTime objects.

Properties

Options

Gets the default JsonSerializerOptions used for JSON serialization and deserialization.

public static JsonSerializerOptions Options { get; }

Property Value

JsonSerializerOptions

Methods

DeserializeAsync<T>(Stream, CancellationToken)

Asynchronously deserializes a UTF8 JSON stream to a model object.

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

Parameters

stream Stream

The input stream containing UTF8 JSON.

cancellationToken CancellationToken

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

Returns

ValueTask<T>

A ValueTask<TResult> representing the asynchronous operation. The result contains the deserialized object if successful; otherwise, (null).

Type Parameters

T

Type of model object.

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

Asynchronously serializes the specified value as UTF-8 encoded JSON and writes it to the provided stream.

public static Task SerializeAsync<T>(Stream utf8Json, T? value, CancellationToken cancellationToken)

Parameters

utf8Json Stream

The stream to which the JSON data will be written. The stream must be writable and remain open for the duration of the operation.

value T

The value to serialize. If value is null, the JSON output will represent a null value.

cancellationToken CancellationToken

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

Returns

Task

A task that represents the asynchronous serialization operation.

Type Parameters

T

Remarks

The method does not close or flush the provided stream. The caller is responsible for managing the stream's lifetime.

TryDeserialize<T>(Stream, out T?)

Converts a UTF8 json stream to a model object.

public static bool TryDeserialize<T>(Stream utf8Json, out T? result)

Parameters

utf8Json Stream

UTF8 json stream

result T

Resulting object if successful; otherwise (null).

Returns

bool

True if successful; otherwise false.

Type Parameters

T

Type of model object.

TryDeserialize<T>(Stream, out T?, out JsonException?)

Converts a UTF8 json stream to a model object.

public static bool TryDeserialize<T>(Stream utf8Json, out T? result, out JsonException? exception)

Parameters

utf8Json Stream

UTF8 json stream

result T

Resulting object if successful; otherwise includes exception.

exception JsonException

Resulting exception or (null) if no errors.

Returns

bool

True if successful; otherwise false.

Type Parameters

T

Type of model object.

TryDeserialize<T>(string, out T?)

Converts UTF8 json string to a model object.

public static bool TryDeserialize<T>(string json, out T? result)

Parameters

json string

UTF8 json string.

result T

Resulting object if successful; otherwise (null).

Returns

bool

True if successful; otherwise false.

Type Parameters

T

Type of model object.