Class OverrideEitherConverter<TLeft, TRight>
Converts Either<TLeft, TRight> to and from JSON. Register this converter to override the default deserialization behavior.
Inherited Members
Namespace: Recore.Text.Json.Serialization.Converters
Assembly: Recore.dll
Syntax
public sealed class OverrideEitherConverter<TLeft, TRight> : JsonConverter<Either<TLeft, TRight>>
Type Parameters
Name | Description |
---|---|
TLeft | |
TRight |
Remarks
This converter is made to be used with a closed type and registered through Converters. It is not returned by Recore.Text.Json.Serialization.Converters.EitherConverter.CreateConverter(System.Type,System.Text.Json.JsonSerializerOptions).
Constructors
| Improve this Doc View SourceOverrideEitherConverter(Func<JsonElement, Boolean>)
Initializes an instance of OverrideEitherConverter<TLeft, TRight>.
Declaration
public OverrideEitherConverter(Func<JsonElement, bool> deserializeAsLeft)
Parameters
Type | Name | Description |
---|---|---|
Func<JsonElement, Boolean> | deserializeAsLeft | A delegate that takes a JsonElement representing some JSON and returns
whether it should be deserialized as |
Methods
| Improve this Doc View SourceRead(ref Utf8JsonReader, Type, JsonSerializerOptions)
Deserializes JSON into Either<TLeft, TRight>. This method will call the delegate passed to the constructor to determine how to deserialize the JSON.
Declaration
public override Either<TLeft, TRight> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonReader | reader | |
Type | typeToConvert | |
JsonSerializerOptions | options |
Returns
Type | Description |
---|---|
Either<TLeft, TRight> |
Overrides
Write(Utf8JsonWriter, Either<TLeft, TRight>, JsonSerializerOptions)
Serializes Either<TLeft, TRight> as JSON.
Declaration
public override void Write(Utf8JsonWriter writer, Either<TLeft, TRight> value, JsonSerializerOptions options)
Parameters
Type | Name | Description |
---|---|---|
Utf8JsonWriter | writer | |
Either<TLeft, TRight> | value | |
JsonSerializerOptions | options |