Handle missing members during deserialization
By default, if the JSON payload you're deserializing contains properties that don't exist in the deserialized plain old CLR object (POCO) type, they're simply ignored. Starting in .NET 8, you can specify that all members must be present in the payload. If they're not, a JsonException exception is thrown. You can configure this behavior in one of three ways:
Annotate your POCO type with the
[<xref:System.Text.Json.Serialization.JsonUnmappedMemberHandlingAttribute>]
attribute, specifying either to Skip or Disallow missing members.[JsonUnmappedMemberHandling(JsonUnmappedMemberHandling.Disallow)] public class MyPoco { public int Id { get; set; } } JsonSerializer.Deserialize<MyPoco>("""{"Id" : 42, "AnotherId" : -1 }"""); // JsonException : The JSON property 'AnotherId' could not be mapped to any .NET member contained in type 'MyPoco'.
Set JsonSerializerOptions.UnmappedMemberHandling to either Skip or Disallow.
Customize the JsonTypeInfo contract for the relevant type. (For information about customizing a contract, see Customize a JSON contract.)
Povratne informacije
https://aka.ms/ContentUserFeedback.
Stiže uskoro: Tijekom 2024. postupno ćemo ukinuti servis Problemi sa servisom GitHub kao mehanizam za povratne informacije za sadržaj i zamijeniti ga novim sustavom za povratne informacije. Dodatne informacije potražite u članku:Pošaljite i pogledajte povratne informacije za