In our system, we have this enum and you can see the value starts with 1, not 0.
public enum EndType
{
[Description("DAYEND")]
DayEnd = 1,
[Description("MONTHEND")]
MonthEnd = 2
}
Then we have a request object that exposed through a web api and you can see that the PerformanceEndType doesn't have a default value.
public class AnnualisedPerformanceRequest
{
public EndType PerformanceEndType { get; set; };
public bool UseDateRestrictMethod { get; set; } = false;
}
Then when people post this JSON request to our web API:
{
"UseDateRestrictMethod": true
}
The PerformanceEndType property actually has a value 0, which is not in the enum values we defined.
Of course, we can put a default value on this property for this request.
However, as we have a fair amount of enum properties in different request objects, is it possible to have some JSON setting or something, so when we call JsonConvert.DeserializeObject(request), it can work out that for this enum, the default value is 1 not 0?