json_serializable_generic 1.0.0 copy "json_serializable_generic: ^1.0.0" to clipboard
json_serializable_generic: ^1.0.0 copied to clipboard

A simple library to add json serializable behavior to a class

example/example.dart

import 'package:json_serializable/json_serializable.dart';

import 'models/user_model.dart';

void exampleWithMap() {
  var commonUser = User(id: 1, name: "Dash", age: 10);

  print(commonUser.toMap(excludes: ['id']));

  var parsedUser = JsonSerializable.fromMap<User>(commonUser.toMap());

  print(parsedUser.toMap());
}

void exampleWithJson() {
  var commonUser = User(id: 1, name: "Dash", age: 10);

  print(commonUser.toJson());

  var parsedUser = JsonSerializable.fromJson<User>(commonUser.toJson());

  print(parsedUser.toJson());
}

void main() {
  try {
    exampleWithMap();
    exampleWithJson();
  } catch (e) {
    print(e);
  }
}
1
likes
130
pub points
13%
popularity

Publisher

unverified uploader

A simple library to add json serializable behavior to a class

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

More

Packages that depend on json_serializable_generic