Table of Contents

Class TrellisJsonValidationException

Namespace
Trellis
Assembly
Trellis.Core.dll

Thrown by Trellis JSON converters when a structured value object's invariants are violated during deserialization (e.g., Money's amount/currency rules).

[SuppressMessage("Roslynator", "RCS1194:Implement exception constructors", Justification = "JsonException's protected serialization ctor and 4/5-arg ctors are intentionally not re-exposed; the three standard ctors cover all supported usage.")]
public sealed class TrellisJsonValidationException : JsonException, ISerializable
Inheritance
TrellisJsonValidationException
Implements
Inherited Members
Extension Methods

Remarks

This is a marker subclass of JsonException. Trellis.Asp's ScalarValueValidationMiddleware recognizes it and surfaces the message (and Path, when present) in the resulting Problem Details payload — restoring DX parity with MVC's model-binder error reporting, which already includes per-field JsonException messages.

Plain JsonExceptions (e.g., those thrown by System.Text.Json when a JSON value can't be coerced to a CLR type) are deliberately not surfaced because their messages can include internal type names. Trellis converters opt in to message surfacing by throwing this subclass with a curated message — for example error.GetDisplayMessage() from a Result failure.

Constructors

TrellisJsonValidationException()

Default constructor (RCS1194).

public TrellisJsonValidationException()

TrellisJsonValidationException(string)

Creates an instance with the supplied curated, user-safe message.

public TrellisJsonValidationException(string message)

Parameters

message string

TrellisJsonValidationException(string, Exception)

Wraps an inner exception with the supplied message.

public TrellisJsonValidationException(string message, Exception innerException)

Parameters

message string
innerException Exception

Properties

InvalidInput

Optional structured payload describing per-field violations recovered during deserialization. Populated by CompositeValueObjectJsonConverter when a composite VO's TryCreate returns an Error.InvalidInput.

public Error.InvalidInput? InvalidInput { get; init; }

Property Value

Error.InvalidInput

Remarks

When this property is set, Trellis.Asp's ScalarValueValidationMiddleware emits one wire entry per FieldViolation — keyed by <parentPath>.<leafName> in MVC dot+bracket convention — instead of collapsing all leaves into a single ;-joined string under the parent path. This restores per-field structure that the original JsonException shape (one path + one message) cannot carry.

When null (the default), the inner-exception path has no structured payload — either a plain JsonException from System.Text.Json or a Trellis converter throw without an associated Error.InvalidInput (e.g., missing required property, unsupported primitive type). The middleware falls back to a single entry under the translated parent path with Message as the value.