Class ValueObjectNewtonsoftJsonMvcExtensions
Namespace: AdCodicem.ValueObjects.AspNetCore.NewtonsoftJson
Assembly: AdCodicem.ValueObjects.AspNetCore.NewtonsoftJson.dll
Wires value object support into an MVC application whose request bodies Newtonsoft.Json reads.
public static class ValueObjectNewtonsoftJsonMvcExtensions
Inheritance
object ← ValueObjectNewtonsoftJsonMvcExtensions
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Methods
AddValueObjectsNewtonsoftJson(IMvcBuilder)
Registers value object model binding and serialization on an MVC builder that reads with Newtonsoft.Json, and records the code of the rule a value refused inside a request body broke.
public static IMvcBuilder AddValueObjectsNewtonsoftJson(this IMvcBuilder builder)
Parameters
builder IMvcBuilder
MVC builder, on which AddNewtonsoftJson() is called, before or after this.
Returns
The same builder, so calls can be chained.
Remarks
It calls
It adds
Those settings are the ones MVC writes every response with as well, and they apply to every member of every
body. An application that ran without the converter changes its wire: a numeric or boolean value object is
answered 7 or true, where the type converter wrote "7" or "True", and a boolean
value object sent as a string is refused. A member of type JToken keeps a string
that looks like a date as a string, and reads a number with a fraction as a
It then puts a formatter of its own in place of MVC's Newtonsoft.Json input formatter, at its index: one deriving
from it, built over the same serializer settings and the same TryApplyTo, of
The swap is a post-configuration of InputFormatters.RemoveType<NewtonsoftJsonInputFormatter>() finds this formatter in its place, which
is not of that exact type: remove there every formatter that is a
It does not call AddNewtonsoftJson(), which is the application's choice of serializer. Without it MVC
reads bodies with System.Text.Json, whose formatter
Exceptions
builder is null.