You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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
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.
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?
The text was updated successfully, but these errors were encountered: