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

Default renaming of variables to other cases(eg:snake_case) #4

Open
fabiancrx opened this issue Jul 12, 2020 · 1 comment
Open

Default renaming of variables to other cases(eg:snake_case) #4

fabiancrx opened this issue Jul 12, 2020 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@fabiancrx
Copy link

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.
@D10100111001
Copy link
Contributor

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

@D10100111001 D10100111001 added enhancement New feature or request good first issue Good for newcomers labels Jul 13, 2020
@fabiancrx fabiancrx removed their assignment Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants