Not able convert the JSON value to SmartEnum from request Body in ASP.NET Core Web API application
- Dominant language
- C#
- Stars
- 2.4k
- Forks
- 184
- PR merge metrics
- No merged PRs in 30d
Description
I'm using SmartEnum in a Web API project wherein i have decorated one of the property of a model as shown below
[JsonConverter(typeof(SmartEnumValueConverter))]
public RequestStatus Status { get; set; } = default!;
and i'm accepting the json in a HttpPost body i.e. FromBody attribute. But Asp.net Core is not able to convert the json in to RequestStatus Enum.
I'm sendint the request as below
{
"RequesterId": "309b272f-6369-4744-8bfd-f7b2b2024530",
"requestDisplayID":"1",
"requestDate":"2021-04-04T01:28:00.141Z",
"applicationID":"1",
"approverID":"1",
"jobID":null,
"workloadID":"1",
"Status":1
}
Can you suggest what change need to be done so that Asp.net Core can convert Status:"1" to SmartEnum
I'm using
Ardalis.SmartEnum 2.0.0
Ardalis.SmartEnum.JsonNet 1.0.3
Ardalis.SmartEnum.Utf8Json 1.0.3
Contributor guide
Research direction
Start with the RequestStatus model property, its SmartEnumValueConverter attribute, and the HttpPost FromBody request using the package versions listed. Reproduce the JSON body and inspect the ASP.NET Core model-binding error; done means Status: 1 is converted to RequestStatus.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100