Class ValidatingJsonConverterFactory
- Namespace
- Trellis.Asp.Validation
- Assembly
- Trellis.Asp.dll
Factory for creating validating JSON converters for IScalarValue<TSelf, TPrimitive> types.
public sealed class ValidatingJsonConverterFactory : JsonConverterFactory
- Inheritance
-
ValidatingJsonConverterFactory
- Inherited Members
- Extension Methods
Remarks
This factory is registered with JsonSerializerOptions and automatically creates ValidatingJsonConverter<TValue, TPrimitive> instances for any type implementing IScalarValue<TSelf, TPrimitive>.
Unlike the exception-throwing approach, this factory creates converters that collect validation errors in ValidationErrorsContext for comprehensive error reporting.
Methods
CanConvert(Type)
Determines whether this factory can create a converter for the specified type.
[UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "Value object types are preserved by JSON serialization infrastructure")]
public override bool CanConvert(Type typeToConvert)
Parameters
typeToConvertTypeThe type to check.
Returns
- bool
trueif the type implements IScalarValue<TSelf, TPrimitive>.
CreateConverter(Type, JsonSerializerOptions)
Creates a validating converter for the specified value object type.
[UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "Value object types are preserved by JSON serialization infrastructure")]
[UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "Value object types are preserved by JSON serialization infrastructure")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "JsonConverterFactory is not compatible with Native AOT")]
public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options)
Parameters
typeToConvertTypeThe value object type.
optionsJsonSerializerOptionsThe serializer options.
Returns
- JsonConverter
A validating JSON converter for the value object type.