Annotate JsonKey for correct usage
Currently the parser ignores JsonKey(name) on enums. This enum Permission {
@JsonKey(name: "readonly") READ_ONLY, @JsonKey(name: "owner") OWNER, @JsonKey(name: "member") MEMBER,
}
should generate: const _$PermissionEnumMap = { Permission.READ_ONLY: 'readonly', Permission.OWNER: 'owner', Permission.MEMBER: 'member', };
but it generates: const _$PermissionEnumMap = { Permission.READ_ONLY: 'READ_ONLY', Permission.OWNER: 'OWNER', Permission.MEMBER: 'MEMBER', };
Use @JsonValue for enums. JsonValue supports strings and ints.
But yeah, this could print a warning that explains this at code generation time
Requires a feature in pkg:meta - https://github.com/dart-lang/sdk/issues/47312
Hi, I have the same problem. Any updates on this situation?
No update @jld3103 – waiting on the linked SDK issue 🤷
Thanks, I figured in my case I can work around it using JsonValue, but it would still be nice to have it supported properly.
Unblocked in https://github.com/dart-lang/sdk/commit/9680d387ec7b683c14d580409abb61f72819cd99
Just need to wait until the min SDK is bumped!