Home ValidatingJsonConverter Class
ValidatingJsonConverter Class
Cancel

ValidatingJsonConverter Class

Namespace: Json.Schema.Serialization

Inheritance: ValidatingJsonConverter<T> 🡒 WeaklyTypedJsonConverter<T> 🡒 JsonConverter<T> 🡒 JsonConverter 🡒 object

Implemented interfaces:

  • IWeaklyTypedJsonConverter
  • IValidatingJsonConverter

DO NOT USE THIS CLASS DIRECTLY. INSTEAD, REGISTER THE NON-GENERIC CONVERTER WITH YOUR SERIALIZER OPTIONS. Validates JSON against a schema during deserialization.

Properties

NameTypeSummary
HandleNullbool 
OptionsEvaluationOptionsGets or sets the evaluation options for schema validation.
TypeType 

Constructors

ValidatingJsonConverter<T>(JsonSchema schema, Func<JsonSerializerOptions, JsonSerializerOptions> optionsFactory)

Creates a new instance of Json.Schema.Serialization.ValidatingJsonConverter`1.

Declaration

1
public ValidatingJsonConverter`1(JsonSchema schema, Func<JsonSerializerOptions, JsonSerializerOptions> optionsFactory)
ParameterTypeDescription
schemaJsonSchemaThe JSON schema to validate against.
optionsFactoryFunc<JsonSerializerOptions, JsonSerializerOptions>A factory function to create serializer options without validating converters to avoid recursion.

Methods

Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Reads and validates JSON data against the schema.

Declaration

1
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
ParameterTypeDescription
readerref Utf8JsonReaderThe reader to use for reading JSON.
typeToConvertTypeThe type to convert to.
optionsJsonSerializerOptionsThe serializer options.

Returns

The deserialized object.

ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

Reads a dictionary key from a JSON property name.

Declaration

1
public override T ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
ParameterTypeDescription
readerref Utf8JsonReaderThe System.Text.Json.Utf8JsonReader to read from.
typeToConvertTypeThe type to convert.
optionsJsonSerializerOptionsThe options to use when reading the value.

Returns

The value that was converted.

Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)

Writes the JSON representation of the object.

Declaration

1
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
ParameterTypeDescription
writerUtf8JsonWriterThe writer to use for writing JSON.
valueTThe value to serialize.
optionsJsonSerializerOptionsThe serializer options.

WriteAsPropertyName(Utf8JsonWriter writer, T value, JsonSerializerOptions options)

Writes a dictionary key as a JSON property name.

Declaration

1
public override void WriteAsPropertyName(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
ParameterTypeDescription
writerUtf8JsonWriterThe System.Text.Json.Utf8JsonWriter to write to.
valueTThe value to convert. The value of System.Text.Json.Serialization.JsonConverter`1.HandleNull determines if the converter handles <see langword=”null” /> values.
optionsJsonSerializerOptionsThe options to use when writing the value.
Contents