You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Serializing a struct with the System.Text.Json serializer should serialize all public fields by default, and only exclude fields by default for classes.
Other information
I haven't tested out record types in C# 9, but would expect the behaviour there to be the same as serializing a struct.
The text was updated successfully, but these errors were encountered:
Closing as a dupe of #876. When designing field support in JsonSerializer, we decided to not include fields when serializing and deserializing by default to avoid a breaking change from .NET 3.1 where fields were ignored. See #2192 (comment) for more info. You can opt into field support by setting JsonSerializerOptions.IncludeFields to true or by annotating each field to include with JsonIncludeAttribute.
What's the rationale for including fields by default for structs, but not classes? I think this behavior would be very confusing.
Description
Serializing a struct with the System.Text.Json serializer should serialize all public fields by default, and only exclude fields by default for classes.
Other information
I haven't tested out record types in C# 9, but would expect the behaviour there to be the same as serializing a struct.
The text was updated successfully, but these errors were encountered: