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
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
streamStreamThe input stream containing UTF8 JSON.
cancellationTokenCancellationTokenA 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
TType 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
utf8JsonStreamThe stream to which the JSON data will be written. The stream must be writable and remain open for the duration of the operation.
valueTThe value to serialize. If
valueis null, the JSON output will represent a null value.cancellationTokenCancellationTokenA 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
utf8JsonStreamUTF8 json stream
resultTResulting object if successful; otherwise (null).
Returns
- bool
True if successful; otherwise false.
Type Parameters
TType 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
utf8JsonStreamUTF8 json stream
resultTResulting object if successful; otherwise includes exception.
exceptionJsonExceptionResulting exception or (null) if no errors.
Returns
- bool
True if successful; otherwise false.
Type Parameters
TType 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
jsonstringUTF8 json string.
resultTResulting object if successful; otherwise (null).
Returns
- bool
True if successful; otherwise false.
Type Parameters
TType of model object.