C#C
C#3y ago
LazyGuard

❔ Prevent accepting numeric values as enum

Hello, I have an API that exposes an enum field Vehicle (Car, Bike, Truck) in the POST. The problem is that when I POST a request with a body {"vehicle" :"1" }, it gets accepted and gets automatically converted to Vehicle.Bike.. But something like {"vehicle" :"bar" } results in a bad request, which is what I need !
Any idea on how to stop parsing integer like enum values?
Was this page helpful?