Open hanskokx opened 1 month ago
Yes, it lacks any configurability at all right now. This is because the metadata introspection APIs for macros are not yet implemented (and we are hashing out the details still).
Once it is well supported, we will certainly add this feature (as well as some other configuration options).
There is a solution for this when all your data model's keys follow the same naming convention, which is creating a build.yaml folder in the root of your project.
targets:
$default:
builders:
json_serializable:
options:
field_rename: snake
It also would be nice if we could configure each model's keys naming convention separately.
@FarisArmoush this issue is about the JsonCodable macro, which is different from the JsonSerializable builder (which is a code generator based on build_runner, not a macro).
The
JsonCodable
macro is a colossal step in the right direction, however it lacks an important feature which should be considered. Often, when working with serialized data (in particular, data returned from an API), the field names may differ from the appropriate Dart names. For instance, I've worked with APIs (particularly with Python backends) that would return JSON that looks like this:When using Freezed or JsonSerializable, I could simply annotate the Dart object as thus:
This allows me to map the snake case JSON value to my camel case Dart objects.