domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.25k stars 1.31k forks source link

Suggestion: Use NewtonsoftJson as the default serializer #1590

Closed crclz closed 4 years ago

crclz commented 4 years ago

DotNet world has got used to Newtonsoft.Json. So is the behaviors of many libraries and unit test code of them. For example, MongoDB ObjectId will be serialized as string using NewtonsoftJson, but will be serialized as a complex structure using System.Text.Json. Developers will take some time to find out the cause.

domaindrivendev commented 4 years ago

As System.Text.Json is the default serializer that now ships with ASP.NET Core, I think it makese most sense for Swashbuckle to follow suit. I understand it can cause some confusion but I believe now is the time to do it and better educate people who are using this library. I've been prioritizing issues that are arising out of this so there's plenty of helpful info available by simply searching the issue list. There's also this section of the readme. If you have any other ideas to better support and educate people in this area, I'd be happy to hear them, but I'm not willing to deviate from the ASP.NET Core default.

domaindrivendev commented 4 years ago

Furthermore, this change was introduced with a major version increment, with breaking changes (inlcuding this one) called out in the major version release notes

Swoorup commented 4 years ago

@domaindrivendev apologies for replying on a closed thread. With newtonsoft, custom attributes appears to be recognized by swashbuckle. But with systemtext, it doesn't, hence libraries like this FSharp.SystemTextJson which serializes F# types don't work well with swagger.

https://github.com/Tarmil/FSharp.SystemTextJson/issues/46

Should it be a concern of the library itself to handle OpenApi Generation or Swashbuckle should generate the schema somehow? Any ideas how to proceed? For now I am stuck with Newtonsoft