serializer 0.2.1 copy "serializer: ^0.2.1" to clipboard
serializer: ^0.2.1 copied to clipboard

outdatedDart 1 only

Serialization to JSON using reflectable

example/serializer_example.dart

// Copyright (c) 2016, <your name>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

library serializer.example;

import 'package:serializer/serializer.dart';

@serializable
class ModelA {
  String name;
  num age;

  ModelA([this.name, this.age]);
}

@serializable
class ModelB extends Serialize {
  String city, country;

  ModelB([this.city, this.country]);
}

@serializable
class ModelC extends Serialize {
  String name, password;

  @ignore
  int age;

  ModelC([this.name, this.password, this.age]);
}

main() async {
  await initSerializer();

  ModelA a = new ModelA("toto", 15);
  ModelB b = new ModelB("Paris", "France");
  ModelC c = new ModelC("Alice", "ThereIsNone", 42);

  print(b.toJson());
  print(b.toMap());
  print(c.toJson());

  print(Serializer.toJson(a));
  print(Serializer.toMap(a));

  ModelA A = Serializer.fromJson(Serializer.toJson(a));
  print(Serializer.toJson(A));
}
1
likes
0
pub points
14%
popularity

Publisher

unverified uploader

Serialization to JSON using reflectable

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

reflectable

More

Packages that depend on serializer