Skip to content

Commit f31db59

Browse files
committed
include another feield in explicit toJson test
1 parent 37f8cea commit f31db59

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

json_serializable/test/json_serializable_test.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ void _registerTests(JsonSerializableGenerator generator) {
8484
var expected = generator.useWrappers
8585
? r'''abstract class _$TrivialNestedNullableSerializerMixin {
8686
TrivialNestedNullable get child;
87+
int get otherField;
8788
Map<String, dynamic> toJson() =>
8889
new _$TrivialNestedNullableJsonMapWrapper(this);
8990
}
@@ -93,14 +94,16 @@ class _$TrivialNestedNullableJsonMapWrapper extends $JsonMapWrapper {
9394
_$TrivialNestedNullableJsonMapWrapper(this._v);
9495
9596
@override
96-
Iterable<String> get keys => const ['child'];
97+
Iterable<String> get keys => const ['child', 'otherField'];
9798
9899
@override
99100
dynamic operator [](Object key) {
100101
if (key is String) {
101102
switch (key) {
102103
case 'child':
103104
return _v.child?.toJson();
105+
case 'otherField':
106+
return _v.otherField;
104107
}
105108
}
106109
return null;
@@ -109,7 +112,9 @@ class _$TrivialNestedNullableJsonMapWrapper extends $JsonMapWrapper {
109112
'''
110113
: r'''abstract class _$TrivialNestedNullableSerializerMixin {
111114
TrivialNestedNullable get child;
112-
Map<String, dynamic> toJson() => <String, dynamic>{'child': child?.toJson()};
115+
int get otherField;
116+
Map<String, dynamic> toJson() =>
117+
<String, dynamic>{'child': child?.toJson(), 'otherField': otherField};
113118
}
114119
''';
115120

@@ -124,6 +129,7 @@ class _$TrivialNestedNullableJsonMapWrapper extends $JsonMapWrapper {
124129
var expected = generator.useWrappers
125130
? r'''abstract class _$TrivialNestedNonNullableSerializerMixin {
126131
TrivialNestedNonNullable get child;
132+
int get otherField;
127133
Map<String, dynamic> toJson() =>
128134
new _$TrivialNestedNonNullableJsonMapWrapper(this);
129135
}
@@ -133,14 +139,16 @@ class _$TrivialNestedNonNullableJsonMapWrapper extends $JsonMapWrapper {
133139
_$TrivialNestedNonNullableJsonMapWrapper(this._v);
134140
135141
@override
136-
Iterable<String> get keys => const ['child'];
142+
Iterable<String> get keys => const ['child', 'otherField'];
137143
138144
@override
139145
dynamic operator [](Object key) {
140146
if (key is String) {
141147
switch (key) {
142148
case 'child':
143149
return _v.child.toJson();
150+
case 'otherField':
151+
return _v.otherField;
144152
}
145153
}
146154
return null;
@@ -149,7 +157,9 @@ class _$TrivialNestedNonNullableJsonMapWrapper extends $JsonMapWrapper {
149157
'''
150158
: r'''abstract class _$TrivialNestedNonNullableSerializerMixin {
151159
TrivialNestedNonNullable get child;
152-
Map<String, dynamic> toJson() => <String, dynamic>{'child': child.toJson()};
160+
int get otherField;
161+
Map<String, dynamic> toJson() =>
162+
<String, dynamic>{'child': child.toJson(), 'otherField': otherField};
153163
}
154164
''';
155165

json_serializable/test/src/json_serializable_test_input.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,11 @@ class SuperType {
218218
@JsonSerializable(createFactory: false)
219219
class TrivialNestedNullable {
220220
TrivialNestedNullable child;
221+
int otherField;
221222
}
222223

223224
@JsonSerializable(createFactory: false, nullable: false)
224225
class TrivialNestedNonNullable {
225226
TrivialNestedNonNullable child;
227+
int otherField;
226228
}

0 commit comments

Comments
 (0)