Why don't we see the enum keys in the serialized response? It only works with the keys in a dictionary.
TestMethod]
public void TestMethod5()
{
string response = "{\"risk\":\"LOW\",\"topics\":{\"CAT\":\"LOW\",\"LION\":\"HIGH\"}}";
Resource deserializedResource = JsonConvert.DeserializeObject<Resource>(response);
string serializedResource = JsonConvert.SerializeObject(deserializedResource);
Console.WriteLine(serializedResource);
// actual = {"risk":10,"topics":{"CAT":10,"LION":30}}
// expectation_1 = {"risk":LOW,"topics":{"CAT":LOW,"LION":HIGH}} OR
// expectation_2 = {"risk":10,"topics":{"0":10,"2":30}}
}
// sample resource and enums
public class Resource
{
[JsonProperty("risk")]
public Risk RiskFactor { get; set; }
[JsonProperty("topics")]
public IDictionary<Animal, Risk> Animals { get; set; }
}
public enum Risk
{
LOW = 10,
MEDIUM = 20,
HIGH = 30
}
public enum Animal
{
CAT = 0,
BULL = 1,
LION = 2
}