#### [Abblix\.Jwt](https://www.abblix.com/en/docs/api/abblix-jwt 'index')
### [Abblix\.Jwt](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt 'Abblix\.Jwt')

## JsonWebKeyConverter Class

Custom JSON converter for JsonWebKey that handles polymorphic serialization/deserialization
based on the "kty" \(key type\) discriminator while ensuring the KeyType property is serialized
in both polymorphic and direct serialization scenarios\.

```csharp
public class JsonWebKeyConverter : System.Text.Json.Serialization.JsonConverter<Abblix.Jwt.JsonWebKey>
```

Inheritance [System\.Object](https://learn.microsoft.com/en-us/dotnet/api/system.object 'System\.Object') → [System\.Text\.Json\.Serialization\.JsonConverter](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonconverter 'System\.Text\.Json\.Serialization\.JsonConverter') → [System\.Text\.Json\.Serialization\.JsonConverter&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonconverter-1 'System\.Text\.Json\.Serialization\.JsonConverter\`1')[JsonWebKey](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonconverter-1 'System\.Text\.Json\.Serialization\.JsonConverter\`1') → JsonWebKeyConverter

### Remarks

Looks superficially replaceable by `[JsonPolymorphic(TypeDiscriminatorPropertyName = "kty")]`
+ `[JsonDerivedType]`. It is not, because of how this hierarchy emits "kty" today:
each concrete subtype overrides [KeyType](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey#Abblix.Jwt.JsonWebKey.KeyType 'Abblix\.Jwt\.JsonWebKey\.KeyType') with
`[JsonPropertyName("kty")]` and `[JsonInclude]`, which guarantees "kty" appears
both in polymorphic writes (`JsonSerializer.Serialize<JsonWebKey>(rsaKey)`) and in
direct concrete-type writes (`JsonSerializer.Serialize(rsaKey)` where the compile-time
type is `RsaJsonWebKey`).

Switching to `[JsonPolymorphic]` alone breaks one of those two scenarios:
- Keep the derived `[JsonInclude]` override AND add `[JsonPolymorphic]`
              → "kty" gets written twice in polymorphic context (once by STJ as the discriminator, once by
              the derived property), producing invalid JSON.
- Drop the derived `[JsonInclude]` override → "kty" disappears whenever a
              concrete subtype is serialized directly, because `[JsonPolymorphic]` only writes the
              discriminator when STJ sees the abstract base type.

This converter bridges both write modes by always serializing through the concrete subtype's
own attribute set, so "kty" lands once regardless of the call site. A future replacement is
possible but must also touch every `KeyType` override and ship with a round-trip
regression test that covers polymorphic AND direct serialization paths.
### Methods

## JsonWebKeyConverter\.Read\(Utf8JsonReader, Type, JsonSerializerOptions\) Method {#Abblix.Jwt.JsonWebKeyConverter.Read(System.Text.Json.Utf8JsonReader,System.Type,System.Text.Json.JsonSerializerOptions)}

Reads a [JsonWebKey](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey') from the JSON payload, dispatching to the matching
concrete subtype \([RsaJsonWebKey](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.RsaJsonWebKey 'Abblix\.Jwt\.RsaJsonWebKey'), [EllipticCurveJsonWebKey](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.EllipticCurveJsonWebKey 'Abblix\.Jwt\.EllipticCurveJsonWebKey'),
or [OctetJsonWebKey](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.OctetJsonWebKey 'Abblix\.Jwt\.OctetJsonWebKey')\) based on the `kty` property\.

```csharp
public override Abblix.Jwt.JsonWebKey? Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options);
```
#### Parameters

###### `reader` [System\.Text\.Json\.Utf8JsonReader](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.utf8jsonreader 'System\.Text\.Json\.Utf8JsonReader') {#Abblix.Jwt.JsonWebKeyConverter.Read(System.Text.Json.Utf8JsonReader,System.Type,System.Text.Json.JsonSerializerOptions).reader}

###### `typeToConvert` [System\.Type](https://learn.microsoft.com/en-us/dotnet/api/system.type 'System\.Type') {#Abblix.Jwt.JsonWebKeyConverter.Read(System.Text.Json.Utf8JsonReader,System.Type,System.Text.Json.JsonSerializerOptions).typeToConvert}

###### `options` [System\.Text\.Json\.JsonSerializerOptions](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions 'System\.Text\.Json\.JsonSerializerOptions') {#Abblix.Jwt.JsonWebKeyConverter.Read(System.Text.Json.Utf8JsonReader,System.Type,System.Text.Json.JsonSerializerOptions).options}

#### Returns
[JsonWebKey](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey')

## JsonWebKeyConverter\.Write\(Utf8JsonWriter, JsonWebKey, JsonSerializerOptions\) Method {#Abblix.Jwt.JsonWebKeyConverter.Write(System.Text.Json.Utf8JsonWriter,Abblix.Jwt.JsonWebKey,System.Text.Json.JsonSerializerOptions)}

Writes a [JsonWebKey](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey') to JSON in its concrete\-subtype shape, so the
resulting object includes the `kty` discriminator and every key\-type\-specific
member\.

```csharp
public override void Write(System.Text.Json.Utf8JsonWriter writer, Abblix.Jwt.JsonWebKey value, System.Text.Json.JsonSerializerOptions options);
```
#### Parameters

###### `writer` [System\.Text\.Json\.Utf8JsonWriter](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.utf8jsonwriter 'System\.Text\.Json\.Utf8JsonWriter') {#Abblix.Jwt.JsonWebKeyConverter.Write(System.Text.Json.Utf8JsonWriter,Abblix.Jwt.JsonWebKey,System.Text.Json.JsonSerializerOptions).writer}

###### `value` [JsonWebKey](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey') {#Abblix.Jwt.JsonWebKeyConverter.Write(System.Text.Json.Utf8JsonWriter,Abblix.Jwt.JsonWebKey,System.Text.Json.JsonSerializerOptions).value}

<a id="Abblix.Jwt.JsonWebKeyConverter.Write(System.Text.Json.Utf8JsonWriter,Abblix.Jwt.JsonWebKey,System.Text.Json.JsonSerializerOptions).options"></a>

`options` [System\.Text\.Json\.JsonSerializerOptions](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions 'System\.Text\.Json\.JsonSerializerOptions')
