I am working on an asp .net core api project and have some problems on validating input. For validation I use FluentValidation, many will know that lib. Serialization is done by Newtonsoft.Json. The version of the api is 5.0. So coming to my problem: I have a class with a enum property (code snippets will follow). That property is nullable. Null means in my context, there is no value. If there is a value present and I send null in my update route, the value is set to null (and this means, it is not present). My current validator is configured for the property as folowing:
RuleFor(x => x.myEnum).IsInEnum();
This works nearly fine. Null values are accepted, I transfer the string-value or the numeric value for the enumeration, which is defined like that:
public enum MyGreatEnum
{
[EnumMember(Value = "DAY")]
Day= 1,
[EnumMember(Value = "NIGHT")]
Night=2
}
If I send an empty string ("") to my webapi, it is interpreted as null, which I realy not want. Is there a way to prevent the conversion from "" to null? Or any other possible solution for my struggeling problem?