-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object reference equality should be used when checking for circular references #401
Comments
… instances when checking for circular references in a object graph.
Duplicate of #214 |
…changing the current bahavior unconditionally would cause a breaking change, this change set add the ability to override the behavior by providing a new setting when configuring the serializer. All the configuration paths are supported(JsonSerializerSettings, Json*Attribute, JsonContract, JsonProperty, etc...). See the ReferenceComparisonHandling enum. [ADDED]: ReferenceComparisonHandlingTests
I have checked in an alternative implementation that allow to maintain the legacy behavior. Thanks. |
I prefer the current behavior which lets devs customize logic by overriding Equals. Besides, this is a big breaking change. |
This causes a lot of unnecessary calls to I have made myself a custom build using The equality we want in our code is not necessarily the same we want for |
@johnsparrowuk @JamesNK |
@D3-LucaPiombino your changes look great, much better than my rush job. If it doesn't get pulled into the official repo I will switch to yours. |
… instances when checking for circular references in a object graph.
…changing the current bahavior unconditionally would cause a breaking change, this change set add the ability to override the behavior by providing a new setting when configuring the serializer. All the configuration paths are supported(JsonSerializerSettings, Json*Attribute, JsonContract, JsonProperty, etc...). See the ReferenceComparisonHandling enum. [ADDED]: ReferenceComparisonHandlingTests
Added EqualityComparer to JsonSerializer 3cc797c |
In Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs(252):
(Last commit: 70d3e93) the code:
should be replaced with:
(or a custom ReferenceEqualityComparer can be created and passed to the other overload)
because if the instance contained in value or any entry in the stack overrides object.Equals it can cause the code to report a false positive.
Test case:
I think this behavior was not intended by the author, since checking for circular references in an object graph should only be about referential identity.
The text was updated successfully, but these errors were encountered: