← → or space · progress saves for Continue on the roadmap
Goal
Know why teams generate serialization code without adopting a tool in this level.
What codegen usually solves
- Large models with many fields: hand-written
fromJsondrifts from APIs. - Consistent rules for
null, defaults, renaming keys (@JsonKey(name: 'user_id')), and enums.
Common stack in Dart
- Package
json_annotationmarks models with annotations. - Package
json_serializableplusbuild_runnergenerates*.g.dartfiles withfromJson/toJsonimplementations.
Typical workflow (overview)
- Add dev dependencies:
build_runner,json_serializable, andjson_annotation. - Run
dart run build_runner buildafter changing annotated classes. - Commit generated files if your team policy requires reproducible builds.
When manual JSON is enough
- Learning exercises, tiny DTOs, scripts, and prototypes.
- Full control over error messages and partial parsing.
Practice tasks
- Skim the
json_serializablereadme on pub.dev and list three annotations or options you noticed. - Keep your Week 7 project manual; note one model that would be painful to maintain by hand at 30+ fields.