I have a data object that I've defined in my API using Newtonsoft decorators:
public class DataRequest
{
[JsonProperty("Id")]
public string id { get; set; }
[JsonProperty("Action")]
public ActionType Action { get; set; }
}
The property I have in my object is an enum:
public enum ActionType
{
POST,
DELETE
}
This works well when my API serializes this object when the request has the string "POST" or "DELETE". However, when my request has an unknown value, my DataRequest object is null. Is there a way I can handle this in case my API gets an unexpected value? I was thinking about excepting a string rather than an enum but I would imagine there is something where Newtonsoft or some other lib could do this for me