Skip to content
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

JSON (de)serializer - add support for object references #29600

Closed
Andrzej-W opened this issue May 19, 2019 · 5 comments
Closed

JSON (de)serializer - add support for object references #29600

Andrzej-W opened this issue May 19, 2019 · 5 comments
Labels
area-System.Text.Json enhancement Product code improvement that does NOT require public API changes/additions json-functionality-doc Missing JSON specific functionality that needs documenting
Milestone

Comments

@Andrzej-W
Copy link

To correctly serialize and deserialize object graphs from Entity Framework we need object references (something like this: https://www.newtonsoft.com/json/help/html/PreserveObjectReferences.htm).

Simple example: we want to serialize orders. Orders have references to customers. Two different orders have a reference to exactly the same customer. After deserialization we have to have one customer object and not two different objects with exactly the same property values.

Without this functionality new JSON (de)serializer is in my opinion almost useless in real world business application. Think about Blazor.

To correctly serialize object graphs from Entity Framework we also need support for graph cycles, see here: #29129

@ahsonkhan
Copy link
Member

This is a known limitation of the JsonSerializer for v1, which is intended to be an MVP for the most critical scenarios, given the runway we have. Since S.T.Json is brand new, it is expected that there will be several features within Json.NET that will not be supported for the initial release.

Regardless, I have marked this as a 3.0 milestone for now rather than deferring to future, for discussion.

cc @steveharter, @rynowak, @JamesNK

@WinCPP
Copy link
Contributor

WinCPP commented Jun 5, 2019

@ahsonkhan once the decision is through, may I work on this?

@ahsonkhan
Copy link
Member

once the decision is through, may I work on this?

This issue is marked for future and likely requires some design and/or api work (which would need to go through approval). I don't think we will have a decision any time soon, so I don't think it can easily be picked up yet.

If you prefer to prototype an implementation and propose an API for review, then feel free to take this on. However, we have quite a few 3.0. milestone issues that we are prioritizing atm, and I would recommend try picking one of those up first:
https://github.com/dotnet/corefx/issues?q=is%3Aopen+is%3Aissue+milestone%3A3.0

@WinCPP
Copy link
Contributor

WinCPP commented Jun 6, 2019

Got it @ahsonkhan. I had left a comment in #29000. Please check there.

Thanks!

@jozkee
Copy link
Member

jozkee commented Jan 21, 2020

The preview version for ReferenceHandling feature is here.

var options = new JsonSerializerOptions
{
    ReferenceHandling = ReferenceHandling.Preserve
};

string json = JsonSerializer.Serialize(objectWithLoops, options);

Here's the spec doc including samples and notes about many scenarios.
If you want to add feedback, feel free to leave a comment in https://github.com/dotnet/corefx/issues/41002.

@jozkee jozkee closed this as completed Jan 21, 2020
@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the Future milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json enhancement Product code improvement that does NOT require public API changes/additions json-functionality-doc Missing JSON specific functionality that needs documenting
Projects
None yet
Development

No branches or pull requests

5 participants