Skip to content

Commit

Permalink
fix: account for Newtonsoft JsonPropertyAttribute with null PropertyName
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin committed Sep 9, 2024
1 parent e55eb77 commit e7638f5
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@ private string GetJsonPathOfAnnotatedProperty(
propertyInfo.GetCustomAttribute<JsonPropertyNameAttribute>();
var newtonsoftJsonPropertyAttribute =
propertyInfo.GetCustomAttribute<Newtonsoft.Json.JsonPropertyAttribute>();

var extensionDataAttribute =
propertyInfo.GetCustomAttribute<JsonExtensionDataAttribute>();
bool propertyJsonNameIsRelevant = extensionDataAttribute is null;
if (propertyJsonNameIsRelevant)
{
if (
newtonsoftJsonPropertyAttribute is not null
newtonsoftJsonPropertyAttribute?.PropertyName is not null
&& systemTextJsonPropertyNameAttribute is null
&& newtonsoftJsonPropertyAttribute.PropertyName?.ToLower()
!= propertyInfo.Name.ToLower()
&& !string.Equals(
newtonsoftJsonPropertyAttribute.PropertyName,
propertyInfo.Name,
StringComparison.CurrentCultureIgnoreCase
)
)
{
throw new InconsistentPropertyNamesException(
Expand Down Expand Up @@ -115,10 +117,13 @@ systemTextJsonPropertyNameAttribute is not null
}

if (
newtonsoftJsonPropertyAttribute is not null
newtonsoftJsonPropertyAttribute?.PropertyName is not null
&& systemTextJsonPropertyNameAttribute is not null
&& newtonsoftJsonPropertyAttribute.PropertyName?.ToLower()
!= systemTextJsonPropertyNameAttribute.Name.ToLower()
&& !string.Equals(
newtonsoftJsonPropertyAttribute.PropertyName!,
systemTextJsonPropertyNameAttribute.Name,
StringComparison.CurrentCultureIgnoreCase
)
)
{
throw new InconsistentPropertyNamesException(
Expand Down

0 comments on commit e7638f5

Please sign in to comment.