https://github.com/leynier/automap-dart
An auto mapper for Dart. It allows mapping objects of different classes automatically and manually using JSON serialization.
https://github.com/leynier/automap-dart
automapper dart flutter mapper package pubdev
Last synced: 7 months ago
JSON representation
An auto mapper for Dart. It allows mapping objects of different classes automatically and manually using JSON serialization.
- Host: GitHub
- URL: https://github.com/leynier/automap-dart
- Owner: leynier
- License: mit
- Created: 2021-04-23T06:44:40.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-04-24T16:53:02.000Z (over 4 years ago)
- Last Synced: 2025-03-15T23:17:58.181Z (7 months ago)
- Topics: automapper, dart, flutter, mapper, package, pubdev
- Language: Dart
- Homepage: https://pub.dev/packages/automap
- Size: 10.7 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# AutoMapper for Dart
[](https://pub.dev/packages/lint)
An auto mapper for Dart. It allows mapping objects of different classes automatically and manually using JSON serialization.
## Example
```dart
import 'package:automap/automap.dart';class AutoSource implements AutoMapperModel {
final int x;AutoSource(this.x);
@override
Map toAutoJson() => {'x': x};
}class AutoTarget {
final int x;AutoTarget(this.x);
static AutoTarget fromAutoJson(Map json) =>
AutoTarget(json['x'] as int);
}class ManualSource {
final int x;ManualSource(this.x);
}class ManualTarget {
final int x;ManualTarget(this.x);
}void main() {
AutoMapper.I
..addMap(
AutoTarget.fromAutoJson,
)
..addManualMap(
(source, mapper, params) => AutoSource(source.x),
)
..addManualMap(
(source, mapper, params) => ManualTarget(source.x),
);
final autoSource = AutoSource(5);
final manualSource = ManualSource(5);
final autoTarget = AutoMapper.I.map(
autoSource,
);
final secondAutoSource = AutoMapper.I.map(
autoTarget,
);
final manualTarget = AutoMapper.I.map(
manualSource,
);
// ignore: avoid_print
print('${autoTarget.x}, ${secondAutoSource.x}, ${manualTarget.x}');
}
```