Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macros] add JsonCodable support for enums #55989

Open
jimmyff opened this issue Jun 12, 2024 · 3 comments
Open

[macros] add JsonCodable support for enums #55989

jimmyff opened this issue Jun 12, 2024 · 3 comments
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-json The json macro package type-enhancement A request for a change that isn't a bug

Comments

@jimmyff
Copy link

jimmyff commented Jun 12, 2024

Enum's aren't supported by the JsonCodable macro, this is a bit of a shame as string's don't enforce options and classes are still verbose if you have a lot of enum data types.

Couldn't the enums be generated as built enum classes like built_value does?

@jakemac53
Copy link
Contributor

It definitely is possible to add enum support, it just hasn't been implemented. I will move this to the SDK repo and label it as a feature request.

@jakemac53 jakemac53 transferred this issue from dart-lang/language Jun 12, 2024
@jakemac53 jakemac53 added area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug pkg-json The json macro package labels Jun 12, 2024
@jakemac53 jakemac53 changed the title [macros] JsonCodable enum's "Only classes are supported as field types for serializable classes" [macros] add JsonCodable support for enums Jun 12, 2024
@jimmyff
Copy link
Author

jimmyff commented Jun 13, 2024

Is there a way I could polyfill the solution for now? If the package supported annotations for custom serializer and deserializer (a bit like json_serializable does it with it's JsonKey())?

@jakemac53
Copy link
Contributor

Is there a way I could polyfill the solution for now? If the package supported annotations for custom serializer and deserializer (a bit like json_serializable does it with it's JsonKey())?

The package doesn't support configuration at all because annotations don't work for macros yet.

Note that this package is not ready for production use (the feature is experimental still and will have breaking changes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-json The json macro package type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants