component-detection icon indicating copy to clipboard operation
component-detection copied to clipboard

Migrate from `Newtonsoft.Json` to `System.Text.Json`

Open JamieMagee opened this issue 3 years ago • 3 comments

For a long time Newtonsoft.Json was the best JSON library for .NET. However, since System.Text.Json was added in .NET Core 3.0, it's clearly the future. It's a core part of .NET, so there's no need for an additional dependency, and it's far more performant than Newtonsoft.Json

A couple of things to be aware of:

References:

JamieMagee avatar Aug 26 '22 18:08 JamieMagee

Hi @JamieMagee , I would like to take a stab at it, if this has not been picked up already. Could you answer some of the queries I have, please

Should we explicitly add JsonPropertyName attributes to object properties?

just want to understand the reasoning behind this. I am assuming that JsonProperty attribute can be replaced with JsonPropertyName attribute. But, are you suggesting that we add JsonPropertyName on all object properties? One place, where we have to do this is all the models where JsonObject attribute is used currently, because I think System.Text.Json doesn't have any such attribute.

Should we standardize on Camel Case (exampleVariableName) over PascalCase (ExampleVariableName)?

I saw some classes where CamelCaseNamingStrategy is used but could not find any where PascalCase is being used

Newtonsoft.Json can accept both by default, can System.Text.Json too?

The only built-in property naming policy in System.Text.Json is for camel case We'll have to write custom naming policy to support PascalCase

pn04 avatar Aug 30 '22 20:08 pn04

Another thing to take into consideration (I tried this before -- maybe last year?) is maintaining the manifest output contract. If I remember correctly, there had to be some custom serializer implementations to make it line up.

tevoinea avatar Aug 31 '22 13:08 tevoinea

@tevoina thanks for the pointers

@pn04 based on the info Teo shared someone from the Microsoft side will likely have to pick this item up. Thank you for volunteering though ❤️

JamieMagee avatar Sep 01 '22 20:09 JamieMagee