Skip to content

Instantly share code, notes, and snippets.

@AnthonyGiretti
Created March 7, 2026 23:21
Show Gist options
  • Select an option

  • Save AnthonyGiretti/e8b62c294ccc692e543a53c1320d7299 to your computer and use it in GitHub Desktop.

Select an option

Save AnthonyGiretti/e8b62c294ccc692e543a53c1320d7299 to your computer and use it in GitHub Desktop.
Before .NET 10, enabling strict validation Deserialization
using System.Text.Json;
using System.Text.Json.Serialization;
var options = new JsonSerializerOptions
{
AllowDuplicateProperties = false,
UnmappedMemberHandling = JsonUnmappedMemberHandling.Disallow,
PropertyNameCaseInsensitive = false,
RespectNullableAnnotations = true,
RespectRequiredConstructorParameters = true
};
var user = JsonSerializer.Deserialize<LoginRequest>(jsonPayload, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment