Net Core Json Serializer

The quickest method of converting between JSON text and a.NET object is using the JsonSerializer.The JsonSerializer converts.NET objects into their JSON equivalent and back again by mapping the.NET object property names to the JSON property names and copies the values for you. However, Json.NET is frequently updated and application developers often want to - or even have to - use a specific version. Thus, we want to remove the dependency from ASP.NET Core 3.0 to Json.NET so that customers can choose which version to use, without fearing they might accidentally break the underlying platform. ASP.NET Core - Json serializer settings Enum as string and ignore null values - Startup.cs.

ASP.NET Core - Json serializer settings Enum as string and ignore null values
Startup.cs
publicclassStartup
{
publicIServiceProviderConfigureServices(IServiceCollectionservices)
{
services.AddMvc().AddJsonOptions(options=>
{
options.SerializerSettings.Converters.Add(newNewtonsoft.Json.Converters.StringEnumConverter());
options.SerializerSettings.NullValueHandling=Newtonsoft.Json.NullValueHandling.Ignore;
});
}
}

commented Mar 27, 2018

You saved me! Thanks bro!

commented Apr 13, 2018

You saved me! Thanks bro!

commented Apr 27, 2018

You saved me! Thanks bro!

commented May 14, 2018

You saved me! Thanks bro!

commented May 22, 2018

You saved me! Thanks bro!

commented May 25, 2018

You saved me! Thanks bro!

commented May 31, 2018

You saved me! Thanks bro!

commented Jun 12, 2018

You saved me! Thanks bro!

commented Jun 20, 2018

You saved me! Thanks bro!

commented Jun 27, 2018

You saved me! Thanks bro!

commented Jul 1, 2018

You saved me! Thanks bro!

commented Jul 3, 2018

KING!!!!!!!!!!!!!!!!!!!!

commented Jul 3, 2018

God bless you man ♥♥♥

commented Aug 4, 2018

You are amazing!!!

commented Aug 20, 2018

Amazing!

commented Aug 30, 2018
edited

wait.... 🤔 found 11 lazy commenters. 🙄 Copy pasting the comment? 😯 Come on guys!!!! 😅🤣😆

Also produce string values:

commented Sep 10, 2018
edited

The EnumMemberAttribute is not sufficient for producing string-values but it is an useful addition to control the actual value of the serialized property, e.g.:

... serializing of MyClazz will then produce:

...

EDIT:
I forgot to say:
You saved me! Thanks bro! :-)

commented Sep 13, 2018

Bro! You saved me! Thanks! :-P

commented Sep 20, 2018

You saved me! Thanks bro!

commented Oct 4, 2018

thanks bro

commented Oct 4, 2018

Awesome, thanks!

commented Dec 18, 2018

+1 for the all the brotherly love here.

commented Jan 23, 2019

+100 You saved me too! Thanks bro. Love ya!

commented Jan 30, 2019

You saved me! Thanks bro!

commented Feb 18, 2019

You saved me! Thanks bro!

commented Feb 21, 2019

You saved me! Thanks bro!

commented Feb 21, 2019

You saved me! Thanks bro!

commented Feb 21, 2019

You saved me! Thanks bro!

commented Feb 21, 2019

After 20 saved people you kind of qualify as the enumerator Jesus Christ.

commented Feb 25, 2019

You saved me! Thanks bro!

commented Feb 26, 2019

You saved me! Thanks bro!

commented Mar 1, 2019

You saved me! Thanks bro!

commented Mar 6, 2019

You saved me! Thanks bro!

commented Mar 15, 2019

You saved me! Thanks bro!

commented Mar 15, 2019

You saved me! Thanks bro!

commented Mar 21, 2019

You saved me! Thanks bro!

commented Mar 24, 2019

You saved me! Thanks bro!

commented Mar 25, 2019

You saved me! Thanks bro!

commented Apr 1, 2019

You saved me! Thanks bro!
And thanks @mike-boddin!

commented Apr 1, 2019

Thanks!

commented Apr 12, 2019

Thanks bro!

commented Apr 13, 2019

You saved me! Thanks bro!

commented Apr 24, 2019

You saved me! Thanks bro!

commented Apr 24, 2019

You saved me! Thanks bro! (this absolutely the best comments list on a gist ever)

commented May 3, 2019

You saved me! Thanks bro!

commented May 3, 2019

You saved me! Thanks bro!

commented May 3, 2019

You saved me! Thanks bro!

commented May 14, 2019

You saved me! Thanks bro!

commented May 16, 2019

Saving souls since 2017!

You saved me! Thanks bro!

commented May 17, 2019

You saved me! Thanks bro!

commented May 24, 2019

Thanks.

commented May 28, 2019

You saved me! Thanks bro!

commented Jun 3, 2019

You saved me! Thanks bro!

commented Jun 3, 2019

You saved me! Thanks bro!

commented Jun 11, 2019

You saved me! Thanks bro!

commented Jun 12, 2019

You saved me! Thanks bro!

commented Jun 19, 2019

You saved me! Thanks bro!

commented Jun 19, 2019

You saved me! Thanks bro!

commented Jul 25, 2019

You saved me! Thanks bro!

commented Jul 28, 2019

You saved me! Thanks bro!

commented Aug 7, 2019

You saved me! Thanks bro!

commented Aug 8, 2019

You saved me! Thanks bro!

commented Aug 12, 2019

You saved me! Thanks bro!

commented Aug 14, 2019

Core

You saved me! Thanks bro!

commented Aug 24, 2019

You saved me! Thanks bro!

commented Aug 29, 2019

You saved me! Thanks bro!

commented Aug 31, 2019

Any idea how to use this for .Net Core 3.0?

commented Sep 4, 2019

@lukaszciastko Try something like this to ignore nulls:
services.AddControllers().AddJsonOptions(options => options.JsonSerializerOptions.IgnoreNullValues = true);

commented Sep 6, 2019

You saved me! Thanks bro!

commented Sep 18, 2019

Asp.net Core Json Serializer

You saved me! Thanks bro!

commented Sep 22, 2019

You saved me! Thanks bro!

commented Sep 22, 2019

You saved me! Thanks bro!

commented Sep 24, 2019

Maybe this would help somebody. The same code for .net core 3.0 will look like this:

commented Sep 27, 2019

Thanks its helped after update to .net core 3.0

commented Sep 27, 2019
edited

Maybe this would help somebody. The same code for .net core 3.0 will look like this:

Just add: using System.Text.Json.Serialization;. Unfortunately, it seems Swagger (Swashbuckle.AspNetCore 5.0.0-rc3) is not ready yet to handle this properly as in the generated doc the enum types are marked as int even if they are properly serialized as strings.

You saved me! Thanks bro! ;)

commented Oct 3, 2019

Net Core Json Serializer For Office

thanks @vasua

.net Core 3.0 Json Serializer

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment