All Downloads are FREE. Search and download functionalities are using the official Maven repository.

handlebars.dart.class.mustache Maven / Gradle / Ivy

There is a newer version: 1.0.54
Show newest version
class {{classname}} {
  {{#vars}}{{#description}}/* {{{description}}} */{{/description}}
  {{^isEnum}}
  {{{datatype}}} {{name}} = {{{defaultValue}}};
  {{/isEnum}}
  {{#isEnum}}
  {{{datatype}}} {{name}} = null;
  {{/isEnum}}
  {{#allowableValues}}
  {{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}
  {{/allowableValues}}
  {{/vars}}

  {{classname}}();

  @override
  String toString() {
    return '{{classname}}[{{#vars}}{{name}}=${{name}}, {{/vars}}]';
  }

  {{classname}}.fromJson(Map json) {
    if (json == null) return;
  {{#vars}}
  {{#isDateTime}}
    {{name}} = json['{{baseName}}'] == null ? null : DateTime.parse(json['{{baseName}}']);
  {{/isDateTime}}
  {{^isDateTime}}
    {{name}} = {{#complexType}}{{#isListContainer}}{{complexType}}.listFromJson(json['{{baseName}}']){{/isListContainer}}{{^isListContainer}}{{#isMapContainer}}{{complexType}}.mapFromJson(json['{{baseName}}']){{/isMapContainer}}{{^isMapContainer}}new {{complexType}}.fromJson(json['{{baseName}}']){{/isMapContainer}}{{/isListContainer}}{{/complexType}}{{^complexType}}{{#isListContainer}}(json['{{baseName}}'] as List).map((item) => item as {{items.datatype}}).toList(){{/isListContainer}}{{^isListContainer}}json['{{baseName}}']{{/isListContainer}}{{/complexType}};
  {{/isDateTime}}
  {{/vars}}
  }

  Map toJson() {
    return {
    {{#vars}}
      {{#isDateTime}}'{{baseName}}': {{name}} == null ? '' : {{name}}.toUtc().toIso8601String(){{^@last}},{{/@last}}{{/isDateTime}}{{^isDateTime}}'{{baseName}}': {{name}}{{^@last}},{{/@last}}{{/isDateTime}}
    {{/vars}}
     };
  }

  static List<{{classname}}> listFromJson(List json) {
    return json == null ? new List<{{classname}}>() : json.map((value) => new {{classname}}.fromJson(value)).toList();
  }

  static Map mapFromJson(Map> json) {
    var map = new Map();
    if (json != null && json.length > 0) {
      json.forEach((String key, Map value) => map[key] = new {{classname}}.fromJson(value));
    }
    return map;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy