Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectJsonException

Namespace: AdCodicem.ValueObjects
Assembly: AdCodicem.ValueObjects.Abstractions.dll

A value object refused the value System.Text.Json was reading or writing.

[Serializable]
public sealed class ValueObjectJsonException : JsonException, ISerializable

Inheritance​

object ← Exception ← JsonException ← ValueObjectJsonException

Implements​

ISerializable

Inherited Members​

JsonException.BytePositionInLine, JsonException.LineNumber, JsonException.Message, JsonException.Path, Exception.GetBaseException(), Exception.GetType(), Exception.ToString(), Exception.Data, Exception.HelpLink, Exception.HResult, Exception.InnerException, Exception.Message, Exception.Source, Exception.StackTrace, Exception.TargetSite, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

The converter the generator emits throws it, and so do the converter for a value object written by hand and the converter of AnyEntityId, wherever they refuse a value: a value or a dictionary key a rule rejects, a token of the wrong kind or that the underlying type cannot hold, and a value to write that its type rejects. It is a , so a catch (JsonException) still catches it, and System.Text.Json treats it as any exception a converter throws: it sets and rethrows the same instance.

It carries the code of the rule, which it also stores in under , so that a reader that only knows the data of an exception, such as a logger writing it out, finds it too. reads it from the exception or from one that wraps it. Like every exception of the library, it never carries the value it refused.

Constructors​

ValueObjectJsonException(string?, Type, string)​

Initializes a new instance of the class.

public ValueObjectJsonException(string? message, Type valueObjectType, string errorCode)

Parameters​

message string?

Message naming the value object and the rule, or null for System.Text.Json to write its own, "The JSON value could not be converted to …", followed by the path, as it does for a token it cannot read.

valueObjectType Type

Value object type that refused the value.

errorCode string

Stable, machine-readable code of the violated rule.

Exceptions​

ArgumentNullException

valueObjectType is null.

ArgumentException

errorCode is null or empty.

Properties​

ErrorCode​

Gets the stable, machine-readable code of the violated rule.

public string ErrorCode { get; }

Property Value​

string

Remarks​

The code of the rule that fired, or for a token that is not of the underlying type at all, and for a JSON null, which only a value object that cannot be null is handed.

ValueObjectType​

Gets the value object type that refused the value.

public Type ValueObjectType { get; }

Property Value​

Type