google / google/json_serializable.dart
support decode null value in enum
- Dominant language
- Dart
- Stars
- 1.6k
- Forks
- 461
- Avg merge
- 45m
- Merged PRs (30d)
- 1
Description
v 4.7.0
for decode enum using next function
```
K $enumDecode(
Map enumValues,
Object? source, {
K? unknownValue,
})
```
with
```
if (source == null) {
throw ArgumentError(
'A value must be provided. Supported values: '
'${enumValues.values.join(', ')}',
);
}
```
so if im have next `enumValues` like
```
const _$FeedbackTypeEnumMap = {
FeedbackType.all: null,
FeedbackType.delivery: 'DELIVERY',
FeedbackType.payment: 'PAYMENT',
};
```
I cannot decode null value as `FeedbackType.all` because `if (source == null) throw `
and I have next exception:
> Invalid argument(s): A value must be provided. Supported values: null, DELIVERY, PAYMENT
for what we use the `throw`? if next steps is
```
for (var entry in enumValues.entries)
```
and then
```
if (unknownValue == null) {
throw ArgumentError(
```
Contributor guide
Assessment
This issue has not been assessed yet.