static_mapper 1.0.1 copy "static_mapper: ^1.0.1" to clipboard
static_mapper: ^1.0.1 copied to clipboard

A Dart package for mapping JSON data to strongly typed models with minimal boilerplate.

example/static_mapper_example.dart

import 'package:static_mapper/static_mapper.dart';

class User extends BaseJsonModel {
  late final id = prop<String>('id');
  late final name = prop<String>('name');
  late final age = prop<int>('age', fallback: 0);
  late final isActive = prop<bool>('isActive', fallback: false);

  User(super.json);

  factory User.fromJson(Map<String, dynamic> j) => User(j);

  @override
  Map<String, dynamic> toJson() => json;
}

void main() {
  final userJson = {'id': 'u001', 'name': 'Alice'};

  final user = User(userJson);

  print('ID: ${user.id.value}');
  print('Name: ${user.name.value}');
  print('Age: ${user.age.value}');
  print('Active: ${user.isActive.value}');

  user.age.value = 25;
  user.isActive.value = true;

  print('Updated JSON: ${user.toJson()}');
}
5
likes
155
points
29
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package for mapping JSON data to strongly typed models with minimal boilerplate.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on static_mapper