jsonFactoryBuilder function
Builder
jsonFactoryBuilder(
- BuilderOptions options
Creates and configures a Builder for generating the JsonFactory code.
This builder implements a multi-step process:
- Scans all Dart files in the project
- Identifies classes marked with @jsonModel annotation
- Validates each class has proper fromJson/toJson methods
- Generates a centralized JsonFactory class for type-safe parsing
Configuration in build.yaml:
targets:
$default:
builders:
json_factory_generator:jsonFactoryBuilder:
options:
# Directory for generated file (default: lib/generated)
output_path: lib/generated
# Name of generated file without .dart (default: json_factory)
output_file_name: json_factory
The builder ensures:
- Type safety through strong static typing
- Proper null-safety handling
- Automatic type registration
- Efficient code generation with minimal boilerplate
Implementation
Builder jsonFactoryBuilder(BuilderOptions options) {
return JsonFactoryBuilder(options);
}