Whenever we speak of WebAPI, JSON comes as the default choice of message exchange format, and whenever we deal with JSON in .Net world, Newtonsoft package comes to help as default; but now with the release of .Net Core 3.0, Newtonsoft is no more the default. The default serializer for JSON in .Net core 3.0 is System.Text.Json.

Replace the default formatter “AddJsonFormatters()” with following code block: In case, we have SignalR in our application; then we will have to add JsonProtocol as shown in the below code block: By doing the above we are asking the .Net to consider “System.JSON” as the default serializer for JSON which will have huge performance gain in serialization and deserialization of messages.

One of the biggest drawback with System.Text.Json in core 3.0 is, it does not support nonstring key in dictionary which can be tested in a unit test which is shown in the below code block: To have workaround for this we would require to write Custom Converter which would converts nonstring key of dictionary into string which is being discussed in the link ( https://github.com/dotnet/corefx/issues/40120 ) but it does not consider all scenarios The second drawback with System.Text.Json in core 3.0 is, it is stricter in deserializing json to object which means the existing code would break if json text will have mismatch in datatype which is shown in below code block: The third drawback with new library is with respect to single quote which worked fine with Newtonsoft but breaks with System.Text.Json which is shown in below code block: As quoted in Microsoft documentation, “The library design emphasizes high performance and low memory allocation over an extensive feature set.

Related Articles