omni_mapper_generator 0.5.2
omni_mapper_generator: ^0.5.2 copied to clipboard
A powerful code generator that automates boilerplate mapping conversions using the omni_mapper annotations.
OmniMapper Generator #
Code generator for the omni_mapper package.
This package automatically generates type-safe object-to-object mapping code, eliminating boilerplate for converting between DTOs, Models, Entities, and ViewModels.
Installation #
Add this package as a dev_dependency alongside build_runner, and add omni_mapper to your normal dependencies:
dependencies:
omni_mapper: ^0.1.0
dev_dependencies:
build_runner: ^2.4.0
omni_mapper_generator: ^0.1.0
Features #
- Extension-based mapping — generates clean extension methods on your classes
- Bidirectional mapping — use
target(Model → Entity) orfrom(Entity → Model) - Custom field mapping — rename fields between source and target
- Type converters — handle type mismatches with
OmniConverter - Default values — provide fallbacks for missing fields
- List generation — batch-map iterables automatically
- In-place updates — mutate existing objects without creating new ones
- Multi-mapper — map a single class to multiple targets with
@OmniMappers @OmniFieldAnnotation — fine-grained field-level configuration directly on class properties- Multiple Sources Mapping — combine multiple source objects into a single target object
- Polymorphic Mapping — handle subclasses and inheritance dynamically (
@SubclassMapping) - Dependency Injection & Composition — reference existing injectable mappers (
uses: [OtherMapper]) - Custom Field Expressions — pure Dart code passed as a string (
MappingRule.custom) - Full Freezed/BuiltValue Compatibility — flawless support for Factory Constructors
- Automatic Enum Mapping — map enums by matching names automatically
- Deep Auto-Flattening — map nested objects automatically
- Strict Mode & IgnoreIfNull — enforce complete mappings and support PATCH-like object updates
Usage #
For detailed usage instructions and examples, please refer to the omni_mapper package documentation.
Running the Generator #
# One-time build
dart run build_runner build -d
# Watch mode
dart run build_runner watch -d
License #
This project is licensed under the BSD 3-Clause License — see the LICENSE file for details.