simple_json
simple_json copied to clipboard
Default renaming of variables to other cases(eg:snake_case)
Hi, great work. May I suggest adding a parameter to the JsonObject annotation to override default naming conventions. such:
@JsonObject(fieldRename:FieldRename.snakeCase)
class Person{
final firstName;
}
``
to make the generated Json:
`"{'first_name':'Bob'}"`
instead of :
`"{'firstName':'Bob'}"`
Why? because most the API's I've worked with(might be biased) use snake_cased variables and dart encourages camelCasing.
I know this is currently avalable via the @JsonProperty name field but it is quite tedious to rename each field of a model , specially if it is a big one(although doable).
Let me know if this is a desirable feature, I might try to land a PR if that's the case.
@fabiancrx Thanks for the feedback and idea. Yes, it would be great to support a way to recase the fields to other cases. PR is welcome to add this feature.
It would be great to support some of the popular casing strategies like snake, kebab, pascal, camel, etc in the FieldRename
enum. I would recommend using the recase lib for the casing implementations.
Also, eventually it would be good to support the field renaming at the CustomJsonMapper
level (runtime) to allow users to have this configured globally or on a mapper instance level. This will help with eliminating the need to repeat the same fieldRename
for every class.
Let me know if you have any troubles or need any guidance.