deserialize Enum from {insert type here}. With partial solution(code snippet that can be inserted[needs to fill in filename, enum name, value type]) #147
When the return type is a enum the deserializer is skipped. the body in the switch is empty. I implemented a fromValue for me. This shouldn't be that hard to generate. Maybe something like this would be easier.
everything within {} should be filled in by the code generator.
{filename}.dart
part '{filename}.g.dart';
@JsonEnum(alwaysCreate: true)
...
factory {enum}.fromValue({valueType} value) {
if (_${enum}EnumMap.containsValue(value)) {
return _${enum}EnumMap.entries
.firstWhere((element) => element.value == value)
.key;
} else {
throw ArgumentError('Invalid value for {enum} enum: $value');
}
}
deserialize.dart
case '{enum}':
return {enum}.fromValue(value as {valueType}) as ReturnType;
Description of the bug
When the return type is a enum the deserializer is skipped. the body in the switch is empty. I implemented a fromValue for me. This shouldn't be that hard to generate. Maybe something like this would be easier.
everything within {} should be filled in by the code generator.
{filename}.dart
...
deserialize.dart
Steps to reproduce
Expected behavior
First attempt to fix the deserialize. Does the same as solution above
Logs
No response
Screenshots
No response
Platform
Linux
Library version
latest
Flutter version
latest
Flutter channel
stable
Additional context
No response