Class BoolFromStringConverter
- Namespace
- Crews.PlanningCenter.Api.Converters
- Assembly
- Crews.PlanningCenter.Api.dll
A custom JSON converter that handles boolean values represented as strings in the JSON payload.
public class BoolFromStringConverter : JsonConverter<bool>
- Inheritance
-
BoolFromStringConverter
- Inherited Members
Constructors
BoolFromStringConverter()
public BoolFromStringConverter()
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads a boolean value from a JSON string. Accepts "true", "false", "1", and "0" (case-insensitive) as valid inputs.
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe JSON reader to read from.
typeToConvertTypeThe type to convert to.
optionsJsonSerializerOptionsThe JSON serializer options.
Returns
- bool
The converted boolean value.
Exceptions
- JsonException
Thrown when the value cannot be converted to a boolean.
Write(Utf8JsonWriter, bool, JsonSerializerOptions)
Writes a boolean value as a JSON boolean. This converter does not support writing boolean values as strings.
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe JSON writer to write to.
valueboolThe boolean value to write.
optionsJsonSerializerOptionsThe JSON serializer options.