Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library removeme;
- import 'dart:math';
- import 'package:ebisu/ebisu_utils.dart' as ebisu_utils;
- // custom <additional imports>
- import 'package:plus/pprint.dart';
- // end <additional imports>
- class Person {
- String birthDate;
- String deathDate;
- String retirementDate;
- // custom <class Person>
- // end <class Person>
- Map toJson() {
- return {
- "birthDate": ebisu_utils.toJson(birthDate),
- "deathDate": ebisu_utils.toJson(deathDate),
- "retirementDate": ebisu_utils.toJson(retirementDate),
- };
- }
- static Person fromJson(String json) {
- Map jsonMap = convert.JSON.decode(json);
- Person result = new Person();
- result._fromJsonMapImpl(jsonMap);
- return result;
- }
- static Person fromJsonMap(Map jsonMap) {
- Person result = new Person();
- result._fromJsonMapImpl(jsonMap);
- return result;
- }
- void _fromJsonMapImpl(Map jsonMap) {
- birthDate = jsonMap["birthDate"];
- deathDate = jsonMap["deathDate"];
- retirementDate = jsonMap["retirementDate"];
- }
- static Map randJson() {
- return {
- "birthDate": ebisu_utils.randJson(_randomJsonGenerator, String),
- "deathDate": ebisu_utils.randJson(_randomJsonGenerator, String),
- "retirementDate": ebisu_utils.randJson(_randomJsonGenerator, String),
- };
- }
- }
- person() => new Person();
- class Asset {
- String name;
- int quantity = 1;
- num unitValue = 1.0;
- // custom <class Asset>
- // end <class Asset>
- Map toJson() {
- return {
- "name": ebisu_utils.toJson(name),
- "quantity": ebisu_utils.toJson(quantity),
- "unitValue": ebisu_utils.toJson(unitValue),
- };
- }
- static Asset fromJson(String json) {
- Map jsonMap = convert.JSON.decode(json);
- Asset result = new Asset();
- result._fromJsonMapImpl(jsonMap);
- return result;
- }
- static Asset fromJsonMap(Map jsonMap) {
- Asset result = new Asset();
- result._fromJsonMapImpl(jsonMap);
- return result;
- }
- void _fromJsonMapImpl(Map jsonMap) {
- name = jsonMap["name"];
- quantity = jsonMap["quantity"];
- unitValue = jsonMap["unitValue"];
- }
- static Map randJson() {
- return {
- "name": ebisu_utils.randJson(_randomJsonGenerator, String),
- "quantity": ebisu_utils.randJson(_randomJsonGenerator, int),
- "unitValue": ebisu_utils.randJson(_randomJsonGenerator, num),
- };
- }
- }
- asset() => new Asset();
- class Dossier {
- Map<String,Person> family;
- Map<String,Asset> assets;
- // custom <class Dossier>
- // end <class Dossier>
- Map toJson() {
- return {
- "family": ebisu_utils.toJson(family),
- "assets": ebisu_utils.toJson(assets),
- };
- }
- static Dossier fromJson(String json) {
- Map jsonMap = convert.JSON.decode(json);
- Dossier result = new Dossier();
- result._fromJsonMapImpl(jsonMap);
- return result;
- }
- static Dossier fromJsonMap(Map jsonMap) {
- Dossier result = new Dossier();
- result._fromJsonMapImpl(jsonMap);
- return result;
- }
- void _fromJsonMapImpl(Map jsonMap) {
- // family is Map<String,Person>
- family = {};
- jsonMap["family"].forEach((k,v) {
- family[k] = (v is Map)?
- Person.fromJsonMap(v) :
- Person.fromJson(v);
- });
- // assets is Map<String,Asset>
- assets = {};
- jsonMap["assets"].forEach((k,v) {
- assets[k] = (v is Map)?
- Asset.fromJsonMap(v) :
- Asset.fromJson(v);
- });
- }
- static Map randJson() {
- return {
- "family":
- ebisu_utils.randJsonMap(_randomJsonGenerator,
- () => Person.randJson(),
- "family"),
- "assets":
- ebisu_utils.randJsonMap(_randomJsonGenerator,
- () => Asset.randJson(),
- "assets"),
- };
- }
- }
- dossier() => new Dossier();
- Random _randomJsonGenerator = new Random(0);
- // custom <library removeme>
- main() {
- auto d = dossier()
- ..family = {
- "father" : person()
- ..birthDate = "2001/1/1"
- ..deathDate = "2101/1/1"
- ..retirementDate = "2100/1/1", // Obamacare
- "mother" : person()
- ..birthDate = "2005/1/1"
- ..deathDate = "2125/1/1"
- ..retirementDate = "2100/1/1",
- }
- ..assets = {
- "house" : asset()
- ..name = "Home on the Hill"
- ..unitValue = 120000,
- "car" : asset()
- ..name = "Dodge Dart"
- ..unitValue = 500
- };
- print(jp(d.toJson()));
- }
- // end <library removeme>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement