Skip to content

Base64UrlTextEncoderConverter Class

A JSON converter for handling the serialization and deserialization of byte arrays as Base64 URL-encoded strings.

C#
public class Base64UrlTextEncoderConverter : System.Text.Json.Serialization.JsonConverter<byte[]?>

Inheritance System.ObjectSystem.Text.Json.Serialization.JsonConverterSystem.Text.Json.Serialization.JsonConverter<System.Byte[]> → Base64UrlTextEncoderConverter

Methods

Base64UrlTextEncoderConverter.Read(Utf8JsonReader, Type, JsonSerializerOptions) Method

Reads and converts the JSON token to a byte array.

C#
public override byte[]? Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options);

Parameters

reader System.Text.Json.Utf8JsonReader

The reader to read the JSON token from.

typeToConvert System.Type

The type of object to convert.

options System.Text.Json.JsonSerializerOptions

Options for the serializer.

Returns

System.Byte[]
A byte array if the token is a string, otherwise null.

Exceptions

System.InvalidOperationException
Thrown if the token is not a string or null.

System.Text.Json.JsonException
Thrown if the string is not valid base64url encoding.

Base64UrlTextEncoderConverter.Write(Utf8JsonWriter, byte[], JsonSerializerOptions) Method

Writes a byte array as a Base64 URL-encoded string to the JSON writer.

C#
public override void Write(System.Text.Json.Utf8JsonWriter writer, byte[]? value, System.Text.Json.JsonSerializerOptions options);

Parameters

writer System.Text.Json.Utf8JsonWriter

The writer to write the JSON token to.

value System.Byte[]

The byte array to write.

options System.Text.Json.JsonSerializerOptions

Options for the serializer.