-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes issue 727 [JsonIgnore] attribute ignored when using $expand (#728)
* #277 change contract of IPropertyMapper.MapProperty, so it can now return null if the field should not be serialized at all (as in, ignored) * #277 update implementation of both default MapProperty methods (Newtonsoft.Json and System.Text), so they return null if the field has the JsonIgnore attribute * #277 update unit tests to reflect that MapProperty now returns null if the field has the JsonIgnore attribute * #277 add unit tests for Newtonsoft Json version of MapProperty
- Loading branch information
1 parent
4ad8262
commit fbddff0
Showing
12 changed files
with
173 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Microsoft.AspNetCore.OData/Properties/SRResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
test/Microsoft.AspNetCore.OData.NewtonsoftJson.Tests/JsonPropertyNameMapperTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//----------------------------------------------------------------------------- | ||
// <copyright file="JsonPropertyNameMapperTest.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation and Contributors. All rights reserved. | ||
// See License.txt in the project root for license information. | ||
// </copyright> | ||
//------------------------------------------------------------------------------ | ||
|
||
using Newtonsoft.Json; | ||
using Microsoft.AspNetCore.OData.NewtonsoftJson; | ||
using Microsoft.OData.Edm; | ||
using Microsoft.OData.ModelBuilder; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.OData.Tests.Query.Container | ||
{ | ||
public class JsonPropertyNameMapperTests | ||
{ | ||
[Fact] | ||
public void MapProperty_Maps_PropertyName() | ||
{ | ||
// Arrange | ||
(IEdmModel model, IEdmStructuredType address) = GetOData(); | ||
JsonPropertyNameMapper mapper = new JsonPropertyNameMapper(model, address); | ||
|
||
// Act & Assert | ||
Assert.Equal("Road", mapper.MapProperty("Street")); | ||
|
||
// Act & Assert | ||
Assert.Equal("City", mapper.MapProperty("City")); | ||
|
||
// Act & Assert | ||
Assert.Null(mapper.MapProperty("IgnoreThis")); | ||
} | ||
|
||
private static (IEdmModel, IEdmStructuredType) GetOData() | ||
{ | ||
EdmModel model = new EdmModel(); | ||
EdmComplexType address = new EdmComplexType("NS", "Address"); | ||
address.AddStructuralProperty("City", EdmPrimitiveTypeKind.String); | ||
address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String); | ||
address.AddStructuralProperty("IgnoreThis", EdmPrimitiveTypeKind.String); | ||
model.AddElement(address); | ||
|
||
model.SetAnnotationValue(address, new ClrTypeAnnotation(typeof(JAddress))); | ||
|
||
model.SetAnnotationValue(address.FindProperty("Street"), | ||
new ClrPropertyInfoAnnotation(typeof(JAddress).GetProperty("Street"))); | ||
|
||
model.SetAnnotationValue(address.FindProperty("IgnoreThis"), | ||
new ClrPropertyInfoAnnotation(typeof(JAddress).GetProperty("IgnoreThis"))); | ||
|
||
return (model, address); | ||
} | ||
|
||
private class JAddress | ||
{ | ||
public string City { get; set; } | ||
|
||
[JsonProperty("Road")] | ||
public string Street { get; set; } | ||
|
||
[JsonIgnore] | ||
public string IgnoreThis { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters