⚙️ Fix a FromBody Parameter Deserializing to All-Default Values Because Two Competing JSON Input Formatters Are Registered
Registering both AddNewtonsoftJson() and the default System.Text.Json-based formatters – common during a migration, or when some NuGet package calls AddNewtonsoftJson internally without anyone noticing – puts two input formatters in the pipeline that can disagree on casing and attribute conventions. Whichever one runs first for a given application/json request wins, and if that’s the formatter that doesn’t understand your model’s actual attributes, the body still “deserializes” successfully into an object with every property left at its default value, with no error raised anywhere.
🔎 The Problem
// Startup:
services.AddControllers().AddNewtonsoftJson();
// Model uses a System.Text.Json attribute:
public class CreateUserRequest
{
[JsonPropertyName("user_name")]
public string UserName { get; set; }
}
// Action receives a non-null CreateUserRequest object,
// but UserName is null - Newtonsoft's formatter ran
// first and has no idea what [JsonPropertyName] means.
✅ Fix: Standardize on One JSON Stack for the Whole Pipeline
- Pick exactly one JSON stack for the entire application – Newtonsoft or System.Text.Json – and remove the other’s registration entirely, instead of leaving both present just because some dependency happened to need one of them once.
- If both genuinely must coexist for different reasons (a legacy area needing Newtonsoft’s specific feature set), scope that need with per-controller or per-area formatter configuration instead of registering it globally for the whole app.
- Add a startup-time check – even a simple log line enumerating MvcOptions.InputFormatters – so a future package upgrade that silently re-adds a second JSON formatter gets caught in code review instead of discovered through a support ticket.
🚨 Why This Is Dangerous
- This fails completely silently – no exception, no 400 response, just a successfully bound object full of default values – so never trust “the request bound without error” as proof the body was actually read correctly; validate that meaningfully required fields are non-default before acting on the model.
A model with every property at its default value isn’t empty by accident – something successfully deserialized nothing into it.

