1

I have an API which is initialized as follows:

var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
formatter.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
formatter.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true });

My enum looks similar to following:

public enum EventType
{        
    Value1 = 1,
    Value2 = 5,        
    Value3 = 3,
    Value4 = 4        
}

And the class where it used as follows:

public class ManualEventModel
{
    public Guid Id { get; set; }

    public EventType EventType { get; set; }

    public DateTime Timestamp { get; set; }

    public bool Active { get; set; }
}

Now if I call the API with EventType=Value5 or any other illegal value, I get no error but the value of the property EventType is set to 0.

How do I filter out the illegal values?

Azimuth
  • 2,599
  • 4
  • 26
  • 33

0 Answers0