jsonFactoryBuilder function

Builder jsonFactoryBuilder(
  1. BuilderOptions options
)

Creates and configures a Builder for generating the JsonFactory code.

This builder implements a multi-step process:

  1. Scans all Dart files in the project
  2. Identifies classes marked with @jsonModel annotation
  3. Validates each class has proper fromJson/toJson methods
  4. 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);
}