The package exposes AddToon(...) extension methods for IServiceCollection, IMvcBuilder, and IMvcCoreBuilder.
builder.Services
.AddControllers()
.AddToon();
builder.Services
.AddControllers()
.AddToon(options =>
{
options.Encode.Indent = 2;
options.Encode.Delimiter = ToonDelimiter.COMMA;
options.Encode.KeyFolding = ToonKeyFolding.Off;
options.Encode.ProtocolVersion = ToonProtocolVersion.CustomV4_4;
options.Encode.ObjectArrayLayout = ToonObjectArrayLayout.Columnar;
options.Encode.ByteArrayFormat = ToonByteArrayFormat.Base64String;
}, useAsDefaultFormatter: false);
Before your callback runs, registration uses official V4_4, two-space indentation, comma delimiters, key folding off, IgnoreNullOrEmpty = false, ExcludeEmptyArrays = false, and Base64 byte sequences. Decoding defaults to Auto. The explicit example above opts into custom columnar output; Columnar alone is not valid with an official protocol.
Version scope: Core 0.2.0, runtime 0.3.0, API 0.2.0, and Client 0.2.0.
Encoding defaults to official 4.4. Supply ToonEncodeOptions.ProtocolVersion with a concrete ToonProtocolVersion: V3_0, V4_0 through V4_4, CustomLegacy, or CustomV4_4. Decoding defaults to Auto; ambiguous version-dependent input needs an explicit ToonDecodeOptions.ProtocolVersion. Auto cannot be used for encoding or as a transport version.
Select CustomLegacy to retain the earlier custom wire profile. CustomV4_4 combines nested header groups with row/keyed spills. Custom profiles require compatible readers at both ends and default IgnoreNullOrEmpty and ExcludeEmptyArrays to true. Official profiles default both to false. Set both explicitly false when preserving null, empty-string, and empty-array distinctions matters. Explicit option overrides remain effective when changing versions. Columnar requires a custom protocol selection.
Encoder options and runtime DI encoding default to one-space indentation; decoder options default to two spaces. With explicit decode options, match the producer’s indentation or detect options using the supplied version hint. API registration aligns both widths at two spaces. Byte sequences default to Base64 strings; numeric-array output is an explicit policy choice.
Request X-Toon-Version labels the request body. Request X-Toon-Option-ProtocolVersion independently selects the response format. Response X-Toon-Version labels the actual TOON response. Concrete wire names are 3.0, 4.0 through 4.4, custom-legacy, and custom-4.4.
API 0.2.0 validates version headers and supplied X-Toon-Option-* headers before model binding/body consumption. Malformed, multiple, or conflicting body versions return 400; well-formed unsupported body versions return 415. Malformed response-version requests return 400; well-formed unsupported response versions return 406. Version validation errors use application/problem+json.
X-Toon-Option-Indent takes an integer width from 1 through 16; booleans and out-of-range widths return 400. This HTTP input limit is separate from trusted direct runtime configuration. API indentation defaults to two spaces when no override is supplied.
Client 0.2.0 changes ToonResponseEncodeOverrideOptions.Indent from bool? to int?. Use Indent = 2, or null to omit the override. EncodeOptions.ProtocolVersion controls outbound request bodies; ResponseEncodeOverrides.ProtocolVersion controls response selection. Invalid, unsupported, multiple, or conflicting response-version hints produce ToonClientException. An explicit decoder setting must agree with the response header. Without a header, configured decode options apply, defaulting to Auto.
options.Encode.ByteArrayFormat = ToonByteArrayFormat.Base64String; means byte[], List<byte>, and IEnumerable<byte> are written as compact Base64 values by default. Change it to NumericArray when a consumer needs a JSON-like numeric array shape.
useAsDefaultFormatter controls formatter ordering:
false: append TOON formatters to MVC collectionstrue: insert TOON formatters at the front so they become the preferred formatter choiceToonServiceOptionsIToonServiceToonInputFormatterToonOutputFormatterapplication/toon and text/toonThe package avoids duplicate formatter registration when the formatters are already present in MVC options.
Source usage reference: DevOp.Toon.API README.