Class ResourceStatesConverter
- Namespace
- Tudormobile.Strava.Converters
- Assembly
- Tudormobile.Strava.dll
Custom JSON converter for the ResourceStates enum.
public class ResourceStatesConverter : JsonConverter<ResourceStates>
- Inheritance
-
ResourceStatesConverter
- Inherited Members
Remarks
This converter handles serialization and deserialization of ResourceStates enum values to and from JSON. It supports both numeric (integer) and string representations of the enum values. The Strava API typically returns resource_state as an integer (1, 2, or 3).
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to a ResourceStates enum value.
public override ResourceStates Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader to read JSON from.
typeToConvertTypeThe type to convert (always ResourceStates).
optionsJsonSerializerOptionsSerializer options to use during conversion.
Returns
- ResourceStates
A ResourceStates enum value. Returns Unknown if the value cannot be parsed or is not recognized.
Remarks
This method handles two JSON token types:
- Number: Converts integers (0-3) to the corresponding enum value.
- String: Attempts to parse string representations (e.g., "Meta", "Summary", "Detail").
Write(Utf8JsonWriter, ResourceStates, JsonSerializerOptions)
Writes a ResourceStates enum value as JSON.
public override void Write(Utf8JsonWriter writer, ResourceStates value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write JSON to.
valueResourceStatesThe ResourceStates enum value to write.
optionsJsonSerializerOptionsSerializer options to use during conversion.
Remarks
This method writes the enum value as its numeric representation (0-3) to match the format expected by the Strava API.