Skip to content

Commit 4f7a01f

Browse files
authored
Latest json_serializable caught unnoticed issue with example (#209)
Updated test to catch it
1 parent 89b1d1d commit 4f7a01f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

example/lib/example.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ DateTime _dateTimeFromEpochUs(int us) =>
5959
new DateTime.fromMicrosecondsSinceEpoch(us);
6060
int _dateTimeToEpochUs(DateTime dateTime) => dateTime.microsecondsSinceEpoch;
6161

62-
@JsonSerializable(createToJson: false)
63-
class Item {
62+
@JsonSerializable()
63+
class Item extends Object with _$ItemSerializerMixin {
6464
int count;
6565
int itemNumber;
6666
bool isRushed;

example/lib/example.g.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ Item _$ItemFromJson(Map<String, dynamic> json) => new Item()
9393
..itemNumber = json['itemNumber'] as int
9494
..isRushed = json['isRushed'] as bool;
9595

96+
abstract class _$ItemSerializerMixin {
97+
int get count;
98+
int get itemNumber;
99+
bool get isRushed;
100+
Map<String, dynamic> toJson() => <String, dynamic>{
101+
'count': count,
102+
'itemNumber': itemNumber,
103+
'isRushed': isRushed
104+
};
105+
}
106+
96107
// **************************************************************************
97108
// Generator: JsonLiteralGenerator
98109
// **************************************************************************

example/test/example_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import 'package:test/test.dart';
1010
void main() {
1111
test('JsonSerializable', () {
1212
final person = new Person('Inigo', 'Montoya', new DateTime(1560, 5, 5))
13-
..orders = [new Order(new DateTime.now())];
13+
..orders = [
14+
new Order(new DateTime.now())..item = (new Item()..count = 42)
15+
];
1416

1517
final personJson = _encode(person);
1618

@@ -21,6 +23,7 @@ void main() {
2123
expect(person.lastName, person2.lastName);
2224
expect(person.dateOfBirth, person2.dateOfBirth);
2325
expect(person.orders.single.date, person2.orders.single.date);
26+
expect(person.orders.single.item.count, 42);
2427

2528
expect(_encode(person2), equals(personJson));
2629
});

0 commit comments

Comments
 (0)