-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added field support to JSON serializer #36986
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,8 @@ public JsonSerializerOptions(System.Text.Json.JsonSerializerDefaults defaults) { | |
public System.Text.Encodings.Web.JavaScriptEncoder? Encoder { get { throw null; } set { } } | ||
public bool IgnoreNullValues { get { throw null; } set { } } | ||
public bool IgnoreReadOnlyProperties { get { throw null; } set { } } | ||
public bool IgnoreReadOnlyFields { get { throw null; } set { } } | ||
public bool IncludeFields { get { throw null; } set { } } | ||
public int MaxDepth { get { throw null; } set { } } | ||
public bool PropertyNameCaseInsensitive { get { throw null; } set { } } | ||
public System.Text.Json.JsonNamingPolicy? PropertyNamingPolicy { get { throw null; } set { } } | ||
|
@@ -479,7 +481,7 @@ public abstract partial class JsonConverter | |
internal JsonConverter() { } | ||
public abstract bool CanConvert(System.Type typeToConvert); | ||
} | ||
[System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Enum | System.AttributeTargets.Property | System.AttributeTargets.Struct, AllowMultiple=false)] | ||
[System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Property | System.AttributeTargets.Field, AllowMultiple=false)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test using the attribute on a field, along with JsonIgnoreAttribute, JsonIncludeAttribute, JsonExtensionDataAttribute & JsonPropertyName. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some new tests, but not finished yet. For naming they already exist. |
||
public partial class JsonConverterAttribute : System.Text.Json.Serialization.JsonAttribute | ||
{ | ||
protected JsonConverterAttribute() { } | ||
|
@@ -506,23 +508,23 @@ public sealed partial class JsonConstructorAttribute : System.Text.Json.Serializ | |
{ | ||
public JsonConstructorAttribute() { } | ||
} | ||
[System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple=false)] | ||
[System.AttributeUsageAttribute(System.AttributeTargets.Property | System.AttributeTargets.Field, AllowMultiple=false)] | ||
public sealed partial class JsonExtensionDataAttribute : System.Text.Json.Serialization.JsonAttribute | ||
{ | ||
public JsonExtensionDataAttribute() { } | ||
} | ||
[System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple=false)] | ||
[System.AttributeUsageAttribute(System.AttributeTargets.Property | System.AttributeTargets.Field, AllowMultiple=false)] | ||
public sealed partial class JsonIgnoreAttribute : System.Text.Json.Serialization.JsonAttribute | ||
{ | ||
public JsonIgnoreAttribute() { } | ||
public System.Text.Json.Serialization.JsonIgnoreCondition Condition { get { throw null; } set { } } | ||
} | ||
[System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple = false)] | ||
[System.AttributeUsageAttribute(System.AttributeTargets.Property | System.AttributeTargets.Field, AllowMultiple = false)] | ||
public sealed partial class JsonIncludeAttribute : System.Text.Json.Serialization.JsonAttribute | ||
{ | ||
public JsonIncludeAttribute() { } | ||
} | ||
[System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple=false)] | ||
[System.AttributeUsageAttribute(System.AttributeTargets.Property | System.AttributeTargets.Field, AllowMultiple=false)] | ||
layomia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public sealed partial class JsonPropertyNameAttribute : System.Text.Json.Serialization.JsonAttribute | ||
{ | ||
public JsonPropertyNameAttribute(string name) { } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,22 +5,22 @@ | |
namespace System.Text.Json.Serialization | ||
{ | ||
/// <summary> | ||
/// When placed on a property of type <see cref="System.Collections.Generic.IDictionary{TKey, TValue}"/>, any | ||
/// properties that do not have a matching member are added to that Dictionary during deserialization and written during serialization. | ||
/// When placed on a property or field of type <see cref="System.Collections.Generic.IDictionary{TKey, TValue}"/>, any | ||
/// properties that do not have a matching property or field are added to that Dictionary during deserialization and written during serialization. | ||
/// </summary> | ||
/// <remarks> | ||
/// The TKey value must be <see cref="string"/> and TValue must be <see cref="JsonElement"/> or <see cref="object"/>. | ||
/// | ||
/// During deserializing, when using <see cref="object"/> a "null" JSON value is treated as a <c>null</c> object reference, and when using | ||
/// <see cref="JsonElement"/> a "null" is treated as a JsonElement with <see cref="JsonElement.ValueKind"/> set to <see cref="JsonValueKind.Null"/>. | ||
/// | ||
/// During serializing, the name of the extension data property is not included in the JSON; | ||
/// During serializing, the name of the extension data member is not included in the JSON; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
change to property or field here and below. |
||
/// the data contained within the extension data is serialized as properties of the JSON object. | ||
/// | ||
/// If there is more than one extension property on a type, or it the property is not of the correct type, | ||
/// If there is more than one extension member on a type, or it the member is not of the correct type, | ||
/// an <see cref="InvalidOperationException"/> is thrown during the first serialization or deserialization of that type. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] | ||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] | ||
public sealed class JsonExtensionDataAttribute : JsonAttribute | ||
{ | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test using this option.