© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
30 replies
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" }
{"vehicle" :"1" }
, it gets accepted and gets automatically converted to Vehicle.Bike.. But something like
{"vehicle" :"bar" }
{"vehicle" :"bar" }
results in a bad request, which is what I need !
Any idea on how to stop parsing integer like enum values?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Duplicate enum values serialization problems
C#CC# / help
2y ago
❔ Compare Enum Values with submitted value
C#CC# / help
4y ago
Get values from an Enum class and perform checking
C#CC# / help
4y ago