Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core 3.0 StringEnumConverter not serializing as string

When decorating your enum with:

[JsonConverter(typeof(StringEnumConverter))]
public EventEntity Entity { get; set; }

And serializing it with JsonConvert.SerializeObject(myEvent)

You may notice that the enum is not serialized as a string but as the default integer.

like image 698
Andy Dobedoe Avatar asked Oct 08 '19 14:10

Andy Dobedoe


1 Answers

Simple one really but had me scratching my head for 20 mins or so...

When using the JsonConverter atribute, the first intellisense import is: using System.Text.Json.Serialization

But you should instead use: using Newtonsoft.Json;

like image 185
Andy Dobedoe Avatar answered Oct 18 '22 17:10

Andy Dobedoe