You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Open
singersbalm opened this issue
May 31, 2024
· 0 comments
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;
singersbalm
changed the title
deserialize Enum from String
deserialize Enum from {insert type here}. With partial solution(code snippet that can be inserted[needs to fill in filename, enum name, value type])
May 31, 2024
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
The text was updated successfully, but these errors were encountered: