json_serializable 0.2.0
json_serializable: ^0.2.0 copied to clipboard

outdated Dart 2 incompatible

Generates utilities to aid in serializing to/from JSON.


// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: annotate_overrides
library json_serializable.example;

import 'package:json_serializable/annotations.dart';
part 'example.g.dart';

class Person extends Object with _$PersonSerializerMixin {
  final String firstName;
  @JsonKey(includeIfNull: false)
  final String middleName;
  final String lastName;

  @JsonKey(name: 'date-of-birth', nullable: false)
  final DateTime dateOfBirth;

  @JsonKey(name: 'last-order')
  final DateTime lastOrder;

  @JsonKey(nullable: false)
  List<Order> orders;

  Person(this.firstName, this.lastName, this.dateOfBirth,
      {this.middleName, this.lastOrder, List<Order> orders})
      : this.orders = orders ?? <Order>[];

  factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);

@JsonSerializable(includeIfNull: false)
class Order extends Object with _$OrderSerializerMixin {
  int count;
  int itemNumber;
  bool isRushed;
  Item item;


  factory Order.fromJson(Map<String, dynamic> json) => _$OrderFromJson(json);

@JsonSerializable(createToJson: false)
class Item {
  int count;
  int itemNumber;
  bool isRushed;


  factory Item.fromJson(Map<String, dynamic> json) => _$ItemFromJson(json);

Map get glossaryData => _$glossaryDataJsonLiteral;