google / google/json_serializable.dart
Allow more than one value map to the same enum value with `@JsonValue`
- Dominant language
- Dart
- Stars
- 1.6k
- Forks
- 461
- Avg merge
- 45m
- Merged PRs (30d)
- 1
Description
Currently, we can use `@JsonValue` in an enum to define what value maps to it.
```dart
enum CustomType {
@JsonValue('a')
valueA,
@JsonValue('b')
valueB,
@JsonValue('c')
valueC,
}
```
Now, I want to map more than one value to the same enum value. I cannot do this unless I write a custom `JsonConverter` for the enum.
This issue proposes that we have a way to tell `json_serializable` that we want more than one value to be mapped to our enum value.
For instance:
```dart
enum CustomType {
@JsonValue('valueA')
@JsonValue('a')
valueA,
@JsonValue('valueB')
@JsonValue('b')
valueB,
@JsonValue('valueC')
@JsonValue('c')
valueC,
}
```
Contributor guide
Assessment
This issue has not been assessed yet.