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
readerUtf8JsonReaderThe reader to read from.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsThe 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
writerUtf8JsonWriterThe writer to write to.
valueSportTypesThe SportTypes value to write.
optionsJsonSerializerOptionsThe serializer options.