Using c# 8 and .netcore 3.1.
I've read HERE that Utf8Json library process json serialization and deserialization faster that NewtonsoftJson.
We've recently upgraded our servers code from .netcore 2.2 to 3.1 mostly for performance improvements. Thus, it is reasonable that we also use the best serialization library.
So my questions are:
In
Startup.csthere is thisservices.AddControllers().AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); });
And I want it to use a different library, so I found out that I can use .AddJsonOptions but I cannot figure out how to set default serializer, even after using my google-fu skills.
- Since I've been using
[JsonProperty("<name>")]everywhere in my code in order to reduce json string size, do I need to format everything for the new serializer or is there a way to make him consider the property attribute ? (attribute is Newtonsoft)
Thanks.
@Ori you can use Utf8json in net core 3.1 projects.
Use
[DataMember(Name = "RoleType")] public string Role_Type { get; set; }Instead of
[JsonProperty("<name>")]To use Utf8json formatters in Asp.Net core you need add the formatters as mentioned below.
You can also refer below link for the formatters. https://github.com/neuecc/Utf8Json/blob/master/src/Utf8Json.AspNetCoreMvcFormatter/Formatter.cs
I am using utf8json and its working great for us.