System.Text.Json 10.0
Last reviewed Sep 6, 2026
Prompt Details
Prompt Composition
2prompts
- C# 14106 lines · 4.4K tokens
- System.Text.Json 10.057 lines · 1.8K tokens
Total163 lines · 6.1K tokens
CWE Coverage
- 15
- 20
- 22
- 59
- 78
- 79
- 89
- 94
- 117
- 190
- 201
- 208
- 209
- 214
- 257
- 295
- 323
- 327
- 338
- 362
- 367
- 378
- 426
- 470
- 488
- 502
- 532
- 611
- 636
- 674
- 759
- 770
- 772
- 775
- 798
- 915
- 916
- 918
- 1287
- 1333
- 1395
Prompt Preview
Apply the C# 14 baseline first. These rules cover System.Text.Json 10.0 contracts, input models, polymorphism, converters, naming, numeric handling, depth, DOM use, source generation, output, and diagnostics.
Strict input contracts
- Set
JsonSerializerOptions.AllowDuplicateProperties=falseat untrusted boundaries; its default is true, and divergent first-value versus last-value consumers can turn duplicate names into validation or signature bypasses. - Set
UnmappedMemberHandling=JsonUnmappedMemberHandling.Disallowor apply[JsonUnmappedMemberHandling(JsonUnmappedMemberHandling.Disallow)]where extra fields must fail; the defaultSkipsilently ignores them. - Review every
[JsonExtensionData]property because it intentionally captures otherwise unmapped fields and can reintroduce overposting or ambiguous round trips. - Deserialize into narrow request DTOs and keep tenant, owner, role, status, price, discriminator, and audit fields out of writable contracts.
- Mark required members with
requiredor[JsonRequired], then perform semantic validation; presence does not makenull, empty, out-of-range, or unauthorized values valid.
Constructor and naming behavior
- Set
RespectRequiredConstructorParameters=truewhen non-optional constructor parameters must be present; it is false by default unless the application enables the corresponding feature switch or selectsJsonSerializerDefaults.Strict. - If enabling
RespectNullableAnnotations, remember it checks only supported non-generic member annotations, not root values, generic collection elements, or