json_serializable.dart
json_serializable.dart copied to clipboard
Configure fieldRename for enums in build.yaml
We have now support for fieldRename
on a per-enum basis (rather than per-value), which simplifies the setup.
In our case, all enums coming from the backend are serialized in PascalCase, so it would be great to have an option to configure it in build.yaml
, the same as we can do for other fields with field_rename
.
I need it too
Seems to work or am I missing something? Just add the following to build.yaml -->
targets:
$default:
builders:
json_serializable:
options:
field_rename: snake
@JPM84 – nope. This does fields within a class. The request here is for enum values.
I'm looking into this and I'm taking a stab at it. I I've got it more or less working now but I do have a big question mark to solve left.
Currently I've implemented it so the JsonEnum
config is read from the same place as JsonSerializable
, but that would mean that field_rename would always be shared between the two.
For example this:
targets:
$default:
builders:
json_serializable:
options:
field_rename: kebab
would result in kebab-case as fallback for all Enums and classes annotated with JsonSerializable.
Any ideas or recommendations on how we should solve this properly?
Ping @kevmoo 😊
I just stumbled upon this. It was a bit of a paper cut, I didn't expect field_rename
not to work for JsonEnum
(indeed build.yaml
configurations are documented as "global").
It also felt more like a bug, rather than a missing feature, or a lack of documentation.
Any progress on this? Just encountered this when adding the constant_identifier_names
lint on a project with a bunch of notCamelCase enum fields.
Is there any particular reason why field_rename
in build.yaml
shouldn't affect enums? If there is, we could also have json_field_rename
or something.