Search code examples
jsonenumsdeserialization

Deserializing a number from a Json file into an Enum


I am having issues deserializing a number into an Enum using JsonConvert.
In other words, I am trying to do exactly what is in this thread.
The problem is that not only it dates from 2015, but also that nobody provided an actual answer to that thread.

I also looked at a couple of other similar threads, but they are not quite solving my issue. As you can see from the above link, the idea is to reconstruct an object when de-serializing and pass in an Enum to the constructor.


Solution

  • the tread contains only one class parameter, so I deserialized parameters without any problem, enumerations were deserialized correctly too

    using Newtonsoft.Json;
    
    List<Parameter> parameters = JArray.Parse(json)[0]["Tests"][0]["Parameters"]
                                                          .ToObject<List<Parameter>>();