json_serializable 0.1.0+1 copy "json_serializable: ^0.1.0+1" to clipboard
json_serializable: ^0.1.0+1 copied to clipboard

outdatedDart 1 only

Generates utilities to aid in serializing to/from JSON.

example/example.dart

// 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.

library json_serializable.example;

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

@JsonSerializable()
class Person extends Object with _$PersonSerializerMixin {
  final String firstName, middleName, lastName;

  @JsonKey('date-of-birth')
  final DateTime dateOfBirth;
  List<Order> orders;

  Person(this.firstName, this.lastName, {this.middleName, this.dateOfBirth});

  factory Person.fromJson(json) => _$PersonFromJson(json);
}

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

  Order();

  factory Order.fromJson(json) => _$OrderFromJson(json);
}

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

  Item();

  factory Item.fromJson(json) => _$ItemFromJson(json);
}

@JsonLiteral('data.json')
Map get glossaryData => _$glossaryDataJsonLiteral;
3336
likes
0
pub points
99%
popularity

Publisher

verified publishergoogle.dev

Generates utilities to aid in serializing to/from JSON.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

analyzer, build, cli_util, path, source_gen

More

Packages that depend on json_serializable