An auto mapper for Dart. It allows mapping objects of different classes automatically and manually using JSON serialization.

Overview

AutoMapper for Dart

style: lint

An auto mapper for Dart. It allows mapping objects of different classes automatically and manually using JSON serialization.

Example

import 'package:automap/automap.dart';

class AutoSource implements AutoMapperModel {
  final int x;

  AutoSource(this.x);

  @override
  Map<String, dynamic> toAutoJson() => {'x': x};
}

class AutoTarget {
  final int x;

  AutoTarget(this.x);

  static AutoTarget fromAutoJson(Map<String, dynamic> 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<AutoSource, AutoTarget>(
      AutoTarget.fromAutoJson,
    )
    ..addManualMap<AutoTarget, AutoSource>(
      (source, mapper, params) => AutoSource(source.x),
    )
    ..addManualMap<ManualSource, ManualTarget>(
      (source, mapper, params) => ManualTarget(source.x),
    );
  final autoSource = AutoSource(5);
  final manualSource = ManualSource(5);
  final autoTarget = AutoMapper.I.map<AutoSource, AutoTarget>(
    autoSource,
  );
  final secondAutoSource = AutoMapper.I.map<AutoTarget, AutoSource>(
    autoTarget,
  );
  final manualTarget = AutoMapper.I.map<ManualSource, ManualTarget>(
    manualSource,
  );
  // ignore: avoid_print
  print('${autoTarget.x}, ${secondAutoSource.x}, ${manualTarget.x}');
}
You might also like...

A cli tool to run Flutter applications and auto hot reload it when files are changed

Dashmon A minimalistic CLI tool to run Flutter applications and auto hot reload it when files are changed. It will watch changes your application code

Oct 6, 2022

Auto is a Flutter automated testing framework developed for testers.

Auto is a Flutter automated testing framework developed for testers.

Auto Auto-A simpler Flutter UI automation test solution. No need to write any code Recording test scripts is very simple Mult

Oct 12, 2022

Args simple - A simple argument parser and handler, integrated with JSON and dart

args_simple A simple argument parser and handler, integrated with JSON and dart:

Jan 22, 2022

Cache json map to local file with Dart:io. Read file with sync api.

local_cache_sync 一个非常简单易用的Flutter本地储存库,适用于在本地储存一列轻量数据(例如用户保存在本地的设备信息,或者缓存一系列用户信息)。 local_cache_sync的所有方法都是同步,而不是异步的。这意味着你不需要使用await就可以获取数据。在flutter中,这

Jun 24, 2022

From JSON to Dart Advanced

From JSON to Dart Advanced

From JSON to Dart Advanced Table of Contents Features Convert from clipboard Convert from selection Convert from clipboard to code generation Convert

Dec 17, 2022

Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques

Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques. The use of dynamic reflection is constrained in order to ensure that the specialized code can be generated and will have a reasonable size.

Dec 31, 2022

An application built using flutter that works as destiny checker, whether our mind wish is as we desire or not with 8 different option.

magic_8_ball_utter A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you s

Feb 3, 2022

A generator to create config class from json files that support many environments

A generator to create config class from json files that support many environments. Motivation If you use a json file to config your applications, perp

Oct 9, 2021

JSON API parser for Flutter

JSON API parser for Flutter

Flutter Japx - JSON:API Decoder/Encoder Lightweight [JSON:API][1] parser that flattens complex [JSON:API][1] structure and turns it into simple JSON a

Dec 20, 2022
Releases(v0.0.3)
Owner
Leynier Gutiérrez González
Computer Science Student and Full Stack Developer
Leynier Gutiérrez González
This package allows programmers to annotate Dart objects in order to Serialize / Deserialize them to / from JSON

This package allows programmers to annotate Dart objects in order to Serialize / Deserialize them to / from JSON. Why? Compatible with all target plat

Alexander Mazuruk 356 Jan 6, 2023
Automatically generate usecase classes from your repository class definition in Dart and Flutter

Repo Case Automatically generate usecase classes from your repository class definition in Dart and Flutter. Check out the official guide on repo_case

Sandro Maglione 5 Jul 30, 2022
Provides simple conversion between Dart classes and Protobuf / Fixnum classes used in gRPC.

grpc_protobuf_convert Provides simple conversion between Dart classes and Protobuf / Fixnum classes used in gRPC. Using the library Add the repo to yo

null 2 Nov 1, 2022
Manually add the extra hitTest area of a widget without changing its size or layout.

extra_hittest_area Language: README.md | 中文简体 Manually add the extra hitTest area of a widget without changing its size or layout. Parent widgets The

FlutterCandies 13 Dec 6, 2022
A CLI tool to help generate dart classes from json returned from API

Json 2 Dart Command line utility Important note There is already a package called json2dart so this package will be called json2dartc ! This project w

Adib Mohsin 38 Oct 5, 2022
Provides null-safety implementation to simplify JSON data handling by adding extension method to JSON object

Lazy JSON Provides null-safety implementation to simplify JSON data handling by adding extension method to JSON object and JSON array. Getting started

Kinnara Digital Studio 0 Oct 27, 2021
A simple Flutter / Dart Utility class for converting complex objects to uri and query string

A simple Flutter / Dart Utility class for converting complex or nested objects to uri and query strings you can follow the the article on how this cla

Opata Joshua 5 Sep 7, 2022
Contains utility functions and classes in the style of dart:collection to make working with collections easier

The collection package for Dart contains a number of separate libraries with utility functions and classes that makes working with collections easier.

Dart 273 Dec 27, 2022
A flutter package that allows you to transform your excel to json

excel_to_json A package that allows you to transform your excel to the following format: Excel To JSON Getting Started At current the package allows y

Vitor Amaral de Melo 0 Nov 7, 2022
A flutter package with classes to help testing applications using the canvas

Canvas test helpers MockCanvas is a utility class for writing tests for canvas operations. It supports the same API as the regular Canvas class from d

Blue Fire 12 Jan 31, 2022