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

Converting database keys in toJson from camelCase to snake_case #3001

Closed
froccawork opened this issue May 9, 2024 · 1 comment
Closed

Converting database keys in toJson from camelCase to snake_case #3001

froccawork opened this issue May 9, 2024 · 1 comment

Comments

@froccawork
Copy link

froccawork commented May 9, 2024

I have many classes and each class has many fields all written in camelCase.
Now when you run the build, the toJson method that is created has the keys in camelCase.
I would like to know if there is a way to make the build create the toJson with the keys in snake_case and not in camelCase

UPDATE
I see that exist @jsonkey("name_field"), but would it be possible to have a key linked to the whole class?

@froccawork froccawork changed the title Converting database keys in toJson from camlCase to snake_case Converting database keys in toJson from camelCase to snake_case May 9, 2024
@simolus3
Copy link
Owner

simolus3 commented May 9, 2024

I think adding default json support to drift was a mistake precisely due to these kinds of problems - drift is supposed to be concerned about accessing databases, but there's builtin JSON serialization (bad for separation of concerns) and it's not that great (because proper packages like json_serializable exist for that, and what's the point of reinventing the wheel).

It requires a little more code from your side, but the best way to fix this is to use your own row classes instead of letting drift generate them for you. They're still verified by drift, but since you then own the row classes you can add your own json annotations and use a proper JSON code generator to implement that.

@simolus3 simolus3 closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants