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

Support ObjectCreationHandling in JsonSerializerOptions like Json.NET does #31518

Closed
tig opened this issue Nov 18, 2019 · 3 comments
Closed

Support ObjectCreationHandling in JsonSerializerOptions like Json.NET does #31518

tig opened this issue Nov 18, 2019 · 3 comments

Comments

@tig
Copy link

tig commented Nov 18, 2019

Json.NET supports ObjectCreationHandling options, but System.Text.Json does not.

https://www.newtonsoft.com/json/help/html/DeserializeObjectCreationHandling.htm

That's disappointing.

Or, am I missing something?

@ahsonkhan
Copy link
Member

ObjectCreationHandling itself is not supported in JsonSerializerOptions today. This is primarily because we didn't see much need for it to prioritize it (you are the first one asking), and of course there are a whole bunch of Json.NET features that S.T.Json doesn't support right out the gate as its first release (some of which we probably won't ever support).

What feature of ObjectCreationHandling do you use and can you share more details around your scenario? What types/collections do you want to serialize/deserialize and what behavior do you expect?

It would help us prioritize the feature and potentially see if there is a viable solution/workaround for you if we can understand your use case (rather than trying to answer a question like: Why is feature X from Json.NET not supported).

For example, are you deserializing lists? Do you want the Reuse behavior or the Auto/Replace behavior? S.T.Json replaces your existing list/collection contents and deserializes based on what's in the JSON payload.

cc @layomia

@tig
Copy link
Author

tig commented Nov 19, 2019

I hadn't actually used Json.NET's ObjectCreationHandling support and may have mis-interpreted what it did. I thought it gave an option for me to deserialize into an existing object instance. E.g. (psuedocode):

class Doc{ 
    public string Title;
    public string Type;
}
...
// jsonString holds instance where doc.Type = "Foo";
Document doc = new Document() { Title = "Title" };
Deserialize<Document>(doc, jsonString);

With this, doc would have doc.Title == "Title" and 'doc.Type == "Foo"`.

Forgive me if I misunderstood. But this is what I'm looking for. I don't want Deserialization to create a new instance, but update an existing instance.

@ahsonkhan
Copy link
Member

Duplicate of https://github.com/dotnet/corefx/issues/37627

Let's move the discussion there.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 5.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants