Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json 1.0.0

dotnet add package Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json --version 1.0.0
                    
NuGet\Install-Package Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json --version 1.0.0
                    
#r "nuget: Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json&version=1.0.0
                    
Install as a Cake Tool

Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json

A Newtonsoft.Json-powered response negotiator for Carter in ASP.NET Core minimal APIs.

About

Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json extends the Codebelt.Extensions.Carter package with a dedicated JSON response negotiator for Carter, capable of serializing response models to JSON format using Newtonsoft.Json.

This package is useful when you need Newtonsoft.Json-specific behavior (for example custom converters, contract resolvers, or legacy JSON compatibility) while keeping Carter modules and content negotiation straightforward.

CSharp Example

Functional-test style sample (same bootstrapping pattern used by this repository):

using System.Net.Http.Headers;
using System.Threading.Tasks;
using Carter;
using Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Formatters;
using Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json;
using Codebelt.Extensions.Carter.Assets;
using Codebelt.Extensions.Xunit.Hosting.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;

using var response = await MinimalWebHostTestFactory.RunAsync(
    services =>
    {
        services.AddNewtonsoftJsonFormatterOptions(o =>
        {
            o.Settings.Converters.Insert(0, new StringEnumConverter(new DefaultNamingStrategy(), false));
        });
        services.AddCarter(configurator: c => c
            .WithModule<WorldModule>()
            .WithResponseNegotiator<NewtonsoftJsonNegotiator>());
        services.AddRouting();
    },
    app =>
    {
        app.UseRouting();
        app.UseEndpoints(endpoints => endpoints.MapCarter());
    },
    _ => { },
    async client =>
    {
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        return await client.GetAsync("/world/statistical-regions");
    });

Program-style usage for production apps (remember to inherit from ICarterModule for your endpoints and add other services as needed):

using Carter;
using Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Formatters;
using Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddNewtonsoftJsonFormatterOptions();
builder.Services.AddCarter(c => c
    .WithResponseNegotiator<NewtonsoftJsonNegotiator>());

var app = builder.Build();
app.MapCarter();
app.Run();
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 75 3/1/2026

Version: 1.0.0
Availability: .NET 10
 
# New Features
- ADDED NewtonsoftJsonNegotiator class in the Codebelt.Extensions.Carter.AspNetCore.Newtonsoft.Json namespace that provides a JSON response negotiator for Carter, capable of serializing response models to JSON format using Newtonsoft.Json