Adding support for custom JsonConverter(s) when deserializing JSON Patch value object#30974
Merged
pranavkm merged 5 commits intodotnet:mainfrom Mar 17, 2021
Merged
Adding support for custom JsonConverter(s) when deserializing JSON Patch value object#30974pranavkm merged 5 commits intodotnet:mainfrom
pranavkm merged 5 commits intodotnet:mainfrom
Conversation
…kes an IContractResolver and hooking it up for ListAdapter - Unit test to verify above works for heterogenous collections
…viderUsesContractResolver Andremi/conversion result provider uses contract resolver
pranavkm
approved these changes
Mar 16, 2021
|
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
pranavkm
reviewed
Mar 16, 2021
src/Features/JsonPatch/src/Internal/ConversionResultProvider.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Pranav K <prkrishn@hotmail.com>
Co-authored-by: Pranav K <prkrishn@hotmail.com>
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.
PR Title
Adding support for custom JsonConverter(s) when deserializing JSON Patch value object
PR Description
When we started using the JSON Patch library we hit an issue with heterogenous collections. To specify what type an object in a heterogenous collection is, we added a "Type" property to the JSON value object. However, regardless of what we supplied in our custom ContractResolver, nothing was getting used when the JObject was converted to a concrete object.
Once we looked at the sources we found out that the JsonPatchDocument.ContractResolver is not used at all when deserializing the value object. So we added an overload that takes an IContractResolver and wired it up for the ListAdapter.
That solved our issue as now our custom JsonConverter is used to read the "Type" property and create the correct object instance. We also added an integration unit test that covers this scenario.