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

A raw "JsonStringType" would save me a lot of unnecessary serialization / deserialization #5167

Closed
chrischandler25 opened this issue Jun 21, 2022 · 1 comment · Fixed by #5756
Assignees
Milestone

Comments

@chrischandler25
Copy link

chrischandler25 commented Jun 21, 2022

Is your feature request related to a problem?

I have an app which stores Json blob data in a database. I want essentially an "AnyType" field on my schema, where the actual json data is returned as a part of the result, rather than as an escaped string that then needs to be parsed in my Javascript client.

Currently I achieve this by reading the database field as a string, parsing into a JsonDocument, which I wrap with a custom IReadOnlyDictionary<string, object?> implementation allowing the HotChocolate serializer to walk the JsonDocument serializing as name value pairs, in a way that I think is somewhat more efficient than actually materializing the blob as a dictionary of scalars & child dictionaries.

In a world of REST controllers, I believe I could do something like

return new ContentResult { Content = myJsonString, ContentType = "application/json" };

which would remove the need to deserialize and then re-serialize entirely.

The solution you'd like

It would be great if a similar concept was possible with HotChocolate, where you could have a JsonStringType type which is essentially a string wrapper, which then just writes using WriteRawValue on the Utf8JsonWriter, or something along those lines.

Product

Hot Chocolate

@chrischandler25 chrischandler25 added the 🎉 enhancement New feature or request label Jun 21, 2022
@michaelstaib
Copy link
Member

We have this on the list for 13. We are thinking to base it on the JsonToken type of System.Text.Json. Implementation wise we have not decided really how we go about it but something in this direction will come.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants