Closed Sadhorsephile closed 1 month ago
If we have a such enum:
BlankEnum: enum: - ''
we'll get this:
// coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint, unused_import import 'package:json_annotation/json_annotation.dart'; @JsonEnum() enum BlankEnum { @JsonValue() (), /// Default value for all unparsed values, allows backward compatibility when adding new values on the backend. $unknown(null); const BlankEnum(this.json); factory BlankEnum.fromJson(dynamic json) => values.firstWhere( (e) => e.json == json, orElse: () => $unknown, ); final dynamic? json; }
If value of enum is empty string, we just use empty as its name:
empty
// coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint, unused_import import 'package:json_annotation/json_annotation.dart'; @JsonEnum() enum BlankEnum { @JsonValue('') empty(''), /// Default value for all unparsed values, allows backward compatibility when adding new values on the backend. $unknown(null); const BlankEnum(this.json); factory BlankEnum.fromJson(dynamic json) => values.firstWhere( (e) => e.json == json, orElse: () => $unknown, ); final dynamic? json; }
Thank you for your contribution. LGTM
Problem
If we have a such enum:
we'll get this:
Solution
If value of enum is empty string, we just use
empty
as its name: