Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ServiceComposer/ServiceComposer.AspNetCore/llms.txt

Use this file to discover all available pages before exploring further.

ResponseSerializationOptions governs how ServiceComposer serializes the assembled ViewModel before writing it to the HTTP response. It is exposed as the ResponseSerialization property on ViewModelCompositionOptions and is configured inside the AddViewModelComposition callback. The options cover three concerns: the default letter casing applied to JSON property names, whether MVC’s output formatter pipeline should handle serialization (enabling content negotiation), and a hook for supplying fully custom JsonSerializerOptions on a per-request basis. An additional mechanism for per-request casing control is available through the Accept-Casing HTTP request header, which overrides DefaultResponseCasing without any code changes.

ResponseSerializationOptions

Class in the ServiceComposer.AspNetCore namespace. Accessed via ViewModelCompositionOptions.ResponseSerialization.

DefaultResponseCasing

public ResponseCasing DefaultResponseCasing { get; set; }
Sets the JSON property naming convention applied to all composed responses when output formatters are not in use. Defaults to ResponseCasing.CamelCase.
DefaultResponseCasing
ResponseCasing
ResponseCasing.CamelCase (default) or ResponseCasing.PascalCase.
builder.Services.AddViewModelComposition(options =>
{
    options.ResponseSerialization.DefaultResponseCasing = ResponseCasing.PascalCase;
});

UseOutputFormatters

public bool UseOutputFormatters { get; set; }
When true, ServiceComposer delegates response writing to the MVC output formatter pipeline, enabling full content negotiation driven by the Accept header (JSON, XML, etc.). MVC services must be registered — call services.AddControllers() or equivalent — before enabling this option. Defaults to false. When set to true alongside a non-default DefaultResponseCasing or a custom JsonSerializerOptions, a warning is logged at startup because formatter-based serialization ignores those settings.
UseOutputFormatters
bool
true to use MVC output formatters; false (default) to use the built-in JSON writer.
builder.Services.AddControllers();
builder.Services.AddViewModelComposition(options =>
{
    options.ResponseSerialization.UseOutputFormatters = true;
});

UseCustomJsonSerializerSettings

public void UseCustomJsonSerializerSettings(
    Func<HttpRequest, JsonSerializerOptions> jsonSerializerSettingsConfig)
Registers a per-request factory that produces a JsonSerializerOptions instance. The factory receives the current HttpRequest, which lets you inspect headers, route values, or any other request data to vary serialization per caller. Has no effect when UseOutputFormatters is true (a warning is logged in that case).
jsonSerializerSettingsConfig
Func<HttpRequest, JsonSerializerOptions>
required
A delegate that receives the current HttpRequest and returns the JsonSerializerOptions to use for that response.
builder.Services.AddViewModelComposition(options =>
{
    options.ResponseSerialization.UseCustomJsonSerializerSettings(request =>
    {
        var serializerOptions = new JsonSerializerOptions
        {
            WriteIndented = request.Headers.ContainsKey("X-Pretty-Print")
        };
        serializerOptions.Converters.Add(new JsonStringEnumConverter());
        return serializerOptions;
    });
});

ResponseCasing Enum

public enum ResponseCasing
{
    CamelCase = 0,
    PascalCase = 1
}
Controls the letter casing convention applied to JSON property names in composed responses.
ValueIntegerDescription
CamelCase0Property names begin with a lowercase letter (productName). This is the default.
PascalCase1Property names begin with an uppercase letter (ProductName).

Per-request casing with Accept-Casing

Clients can override DefaultResponseCasing on a per-request basis by including the Accept-Casing HTTP header. ServiceComposer reads this header and applies the specified casing for that response without any code changes in the handlers.
Header valueApplied casing
casing/camelResponseCasing.CamelCase
casing/pascalResponseCasing.PascalCase
GET /api/products/42
Accept-Casing: casing/pascal
The response JSON will use PascalCase property names regardless of the server-side DefaultResponseCasing setting.

Build docs developers (and LLMs) love