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 for blazor serialiser: Microsoft.JSInterop.Json #2237

Closed
dazinator opened this issue Jun 14, 2019 · 5 comments
Closed

Support for blazor serialiser: Microsoft.JSInterop.Json #2237

dazinator opened this issue Jun 14, 2019 · 5 comments

Comments

@dazinator
Copy link

I just checked out using nswag studio to generate a csharp client, for use within a blazor client side app.

Newtonsoft serializer is not available in blazor client side apps. However microsoft have provided the following json seriliasation mechanism for blazor apps based on Microsoft.JSInterop.Json:

          var thing =  Microsoft.JSInterop.Json.Deserialize<T>(responseText);
          var json =  Microsoft.JSInterop.Json.Serialize(thing);

Sadly I couldn't find any stream based serialisation operations, so when using this serialiser, current methods that use newtonsoft with streams would have to be replaced by the above two (i.e convert to string first).

@danroth27
Copy link

You should be able to use Newtonsoft.Json in client-side Blazor apps. But the framework is switching to use the new System.Text.Json serializer.

@dougbu

@dougbu
Copy link
Contributor

dougbu commented Jun 14, 2019

@dazinator what is the exact issue you're hitting? For example does adding a reference to NewtonSoft.Json to your client-side app lead to an error?

@dazinator
Copy link
Author

dazinator commented Jun 14, 2019

@dougbo
In earlier days, newtonsoft did have some issues running on client side blazor due to lack of Linq - I am guessing based on your enquiry that these are now probably resolved :-) however I still think this issue still makes sense as a feature request - add support for blazor's native JSON serialisation mechanism rather than force a dependency on newtonsoft..

@RicoSuter
Copy link
Owner

RicoSuter commented Jun 15, 2019

Last time I tried Blazor it worked flawlessly with Newtonsoft.Json and the generated clients and models could be used without problems.

I think it doesn't make much sense to support Blazor's serializer as it will eventually use System.Text.Json.

However it makes sense to add an option to generate models (DTOs) to use System.Text.Json's serializer, this is tracked here: RicoSuter/NJsonSchema#1013

I've created an epic regarding System.Text.Json support in general:
#2243

@dazinator
Copy link
Author

dazinator commented Jun 15, 2019

@RicoSuter waiting for System.Text.Json works for me, closing

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

No branches or pull requests

4 participants