fixes issue 727 [JsonIgnore] attribute ignored when using $expand - #728
Merged
Conversation
…ow return null if the field should not be serialized at all (as in, ignored)
…Newtonsoft.Json and System.Text), so they return null if the field has the JsonIgnore attribute
…ull if the field has the JsonIgnore attribute
corranrogue9
reviewed
Nov 1, 2022
| IEdmProperty property = _type.Properties().Single(s => s.Name == propertyName); | ||
| PropertyInfo info = GetPropertyInfo(property); | ||
|
|
||
| JsonIgnoreAttribute jsonIgnore = GetJsonIgnore(info); |
Contributor
There was a problem hiding this comment.
Is this really the direction we want to go? Are we planning to support all System.Text.Json attributes?
Member
There was a problem hiding this comment.
This is newtonsoft related package.
I think we should support most of the newtonsoft property related attributes.
corranrogue9
suggested changes
Nov 1, 2022
corranrogue9
left a comment
Contributor
There was a problem hiding this comment.
We need to decide our policy on which attributes we are supporting
KenitoInc
requested review from
ElizabethOkerio,
KenitoInc,
gathogojr and
habbes
November 17, 2022 11:00
xuzhg
approved these changes
Dec 9, 2022
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #727
Cause of the bug
I found that when using $expand, the MapProperty methods of the default implementations for IPropertyMapper (for System.Text.Json and Newtonsoft.Json) contain code to interpret attributes applied to fields in the view model on their own. That is, they do not rely on the standard libraries to serialise the object, apply attributes, etc.
Also, the only attribute they support is the property to rename a field - JsonProperty for Newtonsoft.Json, JsonPropertyName for System.Text.Json. Every other attribute would be ignored, including JsonIgnore. This explains why the bug is happening.
Solution in this pull request