auto_mappr
2.18.0, released 4 weeks ago by netglade.cz
Code generation package for mapping between different objects with ease.
What it does
AutoMappr generates object-to-object mapping code at pre-compile time, eliminating manual mapping boilerplate. It analyzes source and target classes to automatically map matching fields, and supports complex configurations like field renaming, custom mapping functions, ignored fields, default values, and iterable/map conversions.
AI-written summary of version 2.18.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You frequently map objects between layers (e.g., DTOs to domain models and domain models to UI models).
- You want pre-compile time safety and speed without writing tedious mapping boilerplate by hand.
Skip it when
- You prefer runtime reflection-based mapping without build steps.
- Your project does not use code generation or build_runner.
Strengths
- Moves mapping overhead from runtime to pre-compile time for fast execution.
- Extensive customization options including custom mapping functions, field ignores, defaults, and reverse mapping.
- Works well with packages like equatable and json_serializable.
Weaknesses
- Requires running a build_runner step whenever mappings or models change.
- Strict type inference must be handled carefully using explicit types or generics.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 10
Add auto_mappr, auto_mappr_annotation, and build_runner as dependencies, then run dart run build_runner build.
import 'package:auto_mappr_annotation/auto_mappr_annotation.dart';
import 'my_file.auto_mappr.dart';
@AutoMappr([
MapType<UserDto, User>(),
])
class Mappr extends $Mappr {}
void main() {
final mappr = Mappr();
User user = mappr.convert(UserDto(...));
}Alternatives
Packages that do the same job and could replace auto_mappr.
- freezed
Code generation for immutable classes, tagged unions, and cloning without boilerplate.
96Compare - pigeon
Type-safe code generator for communication between Flutter and host platforms.
90Compare - copy_with_extension
Annotation for generating copyWith extensions code using copy_with_extension_gen.
87Compare - copy_with_extension_gen
Generate type‑safe copyWith extensions for annotated classes and record typedefs.
85Compare
Works with
Packages commonly used together with auto_mappr: ones it builds on, ones built on it, and its own family.
- analyzerauto_mappr depends on itPerforms static analysis of Dart code for tool integration and embedding.
- code_builderauto_mappr depends on itA fluent, builder-based library for generating valid Dart code programmatically.
- built_collectionauto_mappr depends on itImmutable collections based on SDK collections with builder pattern.
- buildauto_mappr depends on itPackage for authoring build_runner compatible code generators.
- equatableauto_mappr depends on itProvides value‑based equality for Dart objects without manual == and hashCode.
- source_genauto_mappr depends on itSource code generation builders and utilities for the Dart build system.
- auto_mappr_annotationauto_mappr depends on itAnnotations for the auto_mappr code-generator to map between objects.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.