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

dart2.serialization.json_serializable.json_serializable_class.mustache Maven / Gradle / Ivy

@JsonSerializable(
  checked: true,
  createToJson: true,
  disallowUnrecognizedKeys: true,
  explicitToJson: true,
)
class {{{classname}}} {
{{>dart_constructor}}

{{#vars}}
  {{#description}}
      /// {{{description}}}
  {{/description}}
  {{^isEnum}}
      {{#minimum}}
          // minimum: {{{minimum}}}
      {{/minimum}}
      {{#maximum}}
          // maximum: {{{maximum}}}
      {{/maximum}}
  {{/isEnum}}
  {{^isBinary}}
  @JsonKey(
    {{#defaultValue}}defaultValue: {{{defaultValue}}},{{/defaultValue}}{{^defaultValue}}nullable: {{isNullable}},{{/defaultValue}}
    name: r'{{{baseName}}}',
    required: {{#required}}true{{/required}}{{^required}}false{{/required}},
  )
  {{/isBinary}}
  {{#isBinary}}
  @JsonKey(ignore: true)
  {{/isBinary}}
  {{{datatypeWithEnum}}} {{{name}}};

{{/vars}}
  @override
  bool operator ==(Object other) => identical(this, other) || other is {{{classname}}} &&
  {{#vars}}
     other.{{{name}}} == {{{name}}}{{^-last}} &&{{/-last}}{{#-last}};{{/-last}}
  {{/vars}}

  @override
  int get hashCode =>
  {{#vars}}
    ({{{name}}} == null ? 0 : {{{name}}}.hashCode){{^-last}} +{{/-last}}{{#-last}};{{/-last}}
  {{/vars}}

  factory {{{classname}}}.fromJson(Map json) => _${{{classname}}}FromJson(json);

  Map toJson() => _${{{classname}}}ToJson(this);

  @override
  String toString() {
    return toJson().toString();
  }

}
{{#vars}}
    {{#isEnum}}
        {{^isContainer}}

{{>serialization/json_serializable/json_serializable_enum_inline}}
        {{/isContainer}}
        {{#isContainer}}
            {{#mostInnerItems}}

{{>serialization/json_serializable/json_serializable_enum_inline}}
            {{/mostInnerItems}}
        {{/isContainer}}
    {{/isEnum}}
{{/vars}}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy