Open
Description
Due to inconsistencies in the data sources my app needs to handle various variants of enum representations e.g.:
{
"myEnum": "VALUE"
}
{
"myEnum": "value"
}
I wish there was a way to tell json_serializable to ignore the case differences and parse these values to MyEnum.value
.
The API I would love to see could be:
In Dart:
JsonKey(ignoreCase: true)
final MyEnum myEnum;
and the generated code would then call toString().toLowerCase()
on the value being passed to enumDecodeNullable
:
$checkedConvert(
json,
'myEnum',
(v) => _$enumDecodeNullable(_$MyEnumEnumMap, v?.toString().toLowerCase(),
unknownValue: MyEnum.unknown)) ??
MyEnum.unknown,