Class BooleanOrStringConverter
- Namespace
- Cloudflare.NET.Core.Json
- Assembly
- Cloudflare.NET.dll
Custom JSON converter for boolean values that can also be represented as strings.
Cloudflare's v2 audit logs API returns the action result as a string ("success"/"failure") while the v1 API returns it as a boolean. This converter handles both formats.
public sealed class BooleanOrStringConverter : JsonConverter<bool>
- Inheritance
-
BooleanOrStringConverter
- Inherited Members
Remarks
true/false- Boolean values"success"/"true"/"1"- String values mapped to true"failure"/"false"/"0"- String values mapped to false""(empty string) ornull- Mapped to false (unknown/indeterminate result)
Methods
Read(ref Utf8JsonReader, Type, JsonSerializerOptions)
Reads and converts the JSON to type bool.
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
readerUtf8JsonReaderThe reader.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.
Returns
- bool
The converted value.
Write(Utf8JsonWriter, bool, JsonSerializerOptions)
Writes a specified value as JSON.
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
Parameters
writerUtf8JsonWriterThe writer to write to.
valueboolThe value to convert to JSON.
optionsJsonSerializerOptionsAn object that specifies serialization options to use.