Skip to content

Commit

Permalink
Serialize all Properties by default (fixes dotnet#41749, dotnet#73021)
Browse files Browse the repository at this point in the history
  • Loading branch information
jogibear9988 committed Jul 31, 2022
1 parent ec5e8b5 commit d864eec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static JsonSerializerOptions Default
private bool _ignoreReadOnlyProperties;
private bool _ignoreReadonlyFields;
private bool _includeFields;
private bool _onlyDeclaredProperties;
private bool _propertyNameCaseInsensitive;
private bool _writeIndented;

Expand Down Expand Up @@ -509,6 +510,23 @@ public bool PropertyNameCaseInsensitive
}
}

/// <summary>
/// Specifies that only members declared at the level of the supplied type's hierarchy should be considered.
/// Inherited members are not considered.
/// </summary>
public bool OnlyDeclaredProperties
{
get
{
return _onlyDeclaredProperties;
}
set
{
VerifyMutable();
_onlyDeclaredProperties = value;
}
}

/// <summary>
/// Defines how the comments are handled during deserialization.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ private void AddPropertiesAndParametersUsingReflection()
{
Debug.Assert(PropertyInfoForTypeInfo.ConverterStrategy == ConverterStrategy.Object);

const BindingFlags BindingFlags =
var BindingFlags BindingFlags =
BindingFlags.Instance |
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.DeclaredOnly;
BindingFlags.NonPublic;

if (this.Options.OnlyDeclaredProperties)
BindingFlags |= BindingFlags.DeclaredOnly;

Dictionary<string, JsonPropertyInfo>? ignoredMembers = null;
bool propertyOrderSpecified = false;
Expand Down

0 comments on commit d864eec

Please sign in to comment.