dart_mappable_builder
4.10.1, released 8 days ago by schultek.dev
Builder that generates dart_mappable code for JSON serialization and data classes.
What it does
Generates mapping code for classes annotated with @MappableClass, handling generics, inheritance, and primary constructors. It integrates with build_runner to produce efficient, type‑safe serializers.
AI-written summary of version 4.10.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need compile‑time JSON (de)serialization with support for generics and inheritance.
- You want a code‑gen alternative to manual toJson/fromJson implementations.
- You prefer a single annotation‑based approach over multiple boilerplate files.
Skip it when
- You prefer a runtime‑only solution without build steps.
- Your project cannot add build_runner or code‑gen dependencies.
Strengths
- Full support for generics, inheritance and primary constructors
- Highly customizable via annotations
- Fast runtime performance because code is generated
Weaknesses
- Requires build_runner and code generation step
- Only works for Dart (no native platform plugins)
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 9
Add dart_mappable_builder to dev_dependencies, configure build_runner, and run `flutter pub run build_runner build`.
import 'package:dart_mappable/dart_mappable.dart';
@MappableClass()
class User with UserMappable {
final String name;
final int age;
const User(this.name, this.age);
}
void main() {
final user = User('Alice', 30);
final json = user.toJson();
final restored = UserMapper.fromMap(json);
print(restored);
}Alternatives
Packages that do the same job and could replace dart_mappable_builder.
- json_annotation
Provides annotation‑based JSON serialization with json_serializable, a widely used alternative.
84Compare - freezed_annotation
Generates immutable data classes and JSON support via freezed, also uses build_runner.
78Compare - built_value
Offers immutable value types with serialization, suitable for complex models.
88Compare
Works with
Packages commonly used together with dart_mappable_builder: ones it builds on, ones built on it, and its own family.
- analyzerdart_mappable_builder depends on itPerforms static analysis of Dart code for tool integration and embedding.
- globdart_mappable_builder depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- dart_styledart_mappable_builder depends on itProvides an API and CLI to format Dart source code automatically.
- builddart_mappable_builder depends on itPackage for authoring build_runner compatible code generators.
- source_gendart_mappable_builder depends on itSource code generation builders and utilities for the Dart build system.
- ansicolordart_mappable_builder depends on itAn xterm-256 color support library for changing terminal text colors and backgrounds.
- dart_mappabledart_mappable_builder depends on itJSON serialization and data classes generator supporting generics, inheritance, and customization.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.