ardalis / ardalis/SmartEnum

Handling nullable

Open
#178 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2.4k
Forks
184
PR merge metrics
No merged PRs in 30d

Description

I have an instance where I am trying to use SmartEnumValueConverter but since the value can be null it throws an error rather than settings the SmartType to null. How can this be handled?

Error: Newtonsoft.Json.JsonSerializationException : Error converting Null to SmartType.

Example:
``` json
{
type: null
}
```

Type can be null, 0, 1, 2, etc.

``` csharp
[JsonConverter(typeof(SmartEnumValueConverter))]
public SmartType? Type { get; set; }
```

Contributor guide

Open the contributing guide

Research direction

Start at the SmartEnumValueConverter entry point and reproduce the Newtonsoft.Json deserialization case using the nullable SmartType property and the JSON example in the issue. Done means a null value deserializes without an exception and sets Type to null, while numeric values such as 0, 1, and 2 continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.