Skip to content

update example for latest stable release #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ dependencies to your `pubspec.yaml`.

```yaml
dependencies:
json_annotation: ^0.2.5
json_annotation: ^1.0.0

dev_dependencies:
build_runner: ^0.9.0
json_serializable: ^0.5.4
json_serializable: ^1.0.0
```

Annotate your code with classes defined in
Expand All @@ -23,9 +23,6 @@ Annotate your code with classes defined in

* See [`lib/example.g.dart`][example_g] for the generated file.

If you would like to use a custom header, or enable the wrapper option, add a
[`build.yaml`][build_config] file and a default target.

Run `pub run build_runner build` to generate files into your source directory.

```console
Expand All @@ -42,6 +39,5 @@ Run `pub run build_runner build` to generate files into your source directory.

[example]: lib/example.dart
[example_g]: lib/example.g.dart
[build_config]: build.yaml
[json_annotation]: https://pub.dartlang.org/packages/json_annotation
[json_serializable]: https://pub.dartlang.org/packages/json_serializable
12 changes: 0 additions & 12 deletions example/build.yaml

This file was deleted.

14 changes: 9 additions & 5 deletions example/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// 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

import 'package:json_annotation/json_annotation.dart';
part 'example.g.dart';

@JsonSerializable()
class Person extends Object with _$PersonSerializerMixin {
class Person {
final String firstName;
@JsonKey(includeIfNull: false)
final String middleName;
Expand All @@ -28,10 +26,12 @@ class Person extends Object with _$PersonSerializerMixin {
: this.orders = orders ?? <Order>[];

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

Map<String, dynamic> toJson() => _$PersonToJson(this);
}

@JsonSerializable(includeIfNull: false)
class Order extends Object with _$OrderSerializerMixin {
class Order {
int count;
int itemNumber;
bool isRushed;
Expand All @@ -49,6 +49,8 @@ class Order extends Object with _$OrderSerializerMixin {
Order(this.date);

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

Map<String, dynamic> toJson() => _$OrderToJson(this);
}

Duration _durationFromMillseconds(int milliseconds) =>
Expand All @@ -60,14 +62,16 @@ DateTime _dateTimeFromEpochUs(int us) =>
int _dateTimeToEpochUs(DateTime dateTime) => dateTime.microsecondsSinceEpoch;

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

Item();

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

Map<String, dynamic> toJson() => _$ItemToJson(this);
}

@JsonLiteral('data.json')
Expand Down
95 changes: 37 additions & 58 deletions example/lib/example.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ environment:
sdk: '>=2.0.0-dev.54 <3.0.0'

dependencies:
json_annotation: ^0.2.5
json_annotation: ^1.0.0

dev_dependencies:
build_runner: ^0.9.0
json_serializable: ^0.5.4
json_serializable: ^1.0.0

# Used by tests. Not required to use `json_serializable`.
path: ^1.5.1
Expand Down
4 changes: 2 additions & 2 deletions example/test/readme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ void _expect(String fileName) {

final _pubspecContent = r'''
dependencies:
json_annotation: ^0.2.5
json_annotation: ^1.0.0

dev_dependencies:
build_runner: ^0.9.0
json_serializable: ^0.5.4
json_serializable: ^1.0.0
''';