Table of Contents

Class ActivityStatsConverter

Namespace
Tudormobile.Strava.Converters
Assembly
Tudormobile.Strava.dll

Custom JSON converter for the ActivityStats class.

public class ActivityStatsConverter : JsonConverter<ActivityStats>
Inheritance
ActivityStatsConverter
Inherited Members

Remarks

This converter handles special deserialization logic for activity statistics from the Strava API. The Strava API sometimes returns empty strings ("") instead of null for missing activity totals, which requires custom handling to properly deserialize into nullable ActivityTotal objects.

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to an ActivityStats object.

public override ActivityStats? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Parameters

reader Utf8JsonReader

The reader to read JSON from.

typeToConvert Type

The type to convert (always ActivityStats).

options JsonSerializerOptions

Serializer options to use during conversion.

Returns

ActivityStats

An ActivityStats object with properly deserialized activity totals.

Remarks

This method handles the Strava API's quirk of returning empty strings ("") for null activity totals. It converts these empty strings to null values for the corresponding ActivityTotal properties.

Write(Utf8JsonWriter, ActivityStats, JsonSerializerOptions)

Writes an ActivityStats object as JSON.

public override void Write(Utf8JsonWriter writer, ActivityStats value, JsonSerializerOptions options)

Parameters

writer Utf8JsonWriter

The writer to write JSON to.

value ActivityStats

The ActivityStats object to write.

options JsonSerializerOptions

Serializer options to use during conversion.

Remarks

This method serializes an ActivityStats object to JSON format compatible with the Strava API. Null ActivityTotal properties are written as empty strings to match Strava API format.