Skip to content

Commit

Permalink
#229 Add test to illustrate lists with null values
Browse files Browse the repository at this point in the history
  • Loading branch information
k-paxian committed Nov 27, 2024
1 parent c5ae571 commit 09242e9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions perf-test/test/unit/test.value.decorators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,41 @@ void testValueDecorators() {
JsonMapper().removeAdapter(adapter);
});

test('List of Lists with null', () {
// given
final json = '''{
"lists": [
null,
null,
[{}, {}, null],
[{}, {}, {}]
]
}''';
final adapter = JsonMapperAdapter(valueDecorators: {
typeOf<List<List<Item>>>(): (value) {
(value as List).removeWhere((x) => x == null);
return value.cast<List<Item>>();
},
typeOf<List<Item>>(): (value) {
(value as List).removeWhere((x) => x == null);
return value.cast<Item>();
}
});
JsonMapper().useAdapter(adapter);

// when
final target = JsonMapper.deserialize<ListOfLists>(json)!;

// then
expect(target.lists?.length, 2);
expect(target.lists?.first.length, 2);
expect(target.lists?.last.length, 3);
expect(target.lists?.first.first, TypeMatcher<Item>());
expect(target.lists?.last.first, TypeMatcher<Item>());

JsonMapper().removeAdapter(adapter);
});

test('List of Lists with constructor', () {
// given
final json = '''{
Expand Down

0 comments on commit 09242e9

Please sign in to comment.