Table of Contents

Class SportTypesConverter

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

Custom JSON converter for the SportTypes enum.

public class SportTypesConverter : JsonConverter<SportTypes>
Inheritance
SportTypesConverter
Inherited Members

Remarks

This converter handles serialization and deserialization of SportTypes enum values to and from JSON. It supports both numeric (integer) and string representations of the enum values. The Strava API typically returns sport_type as a string (e.g., "Run", "Ride").

Methods

Read(ref Utf8JsonReader, Type, JsonSerializerOptions)

Reads and converts the JSON to a SportTypes value. Handles both numeric and string representations of the enum.

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

Parameters

reader Utf8JsonReader

The reader to read from.

typeToConvert Type

The type to convert.

options JsonSerializerOptions

The serializer options.

Returns

SportTypes

The deserialized SportTypes value.

Write(Utf8JsonWriter, SportTypes, JsonSerializerOptions)

Writes the SportTypes value as a numeric value to JSON.

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

Parameters

writer Utf8JsonWriter

The writer to write to.

value SportTypes

The SportTypes value to write.

options JsonSerializerOptions

The serializer options.