dart-lang / sdk

The Dart SDK, including the VM, dart2js, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
9.98k stars 1.54k forks source link

[macros] add JsonCodable support for enums #55989

Open jimmyff opened 1 month ago

jimmyff commented 1 month ago

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 commented 1 month ago

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.

jimmyff commented 1 month ago

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 commented 1 month ago

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).