Skip to content

Commit 58f7d63

Browse files
authored
Links with null values (#124)
1 parent 821a386 commit 58f7d63

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [5.0.5] - 2021-07-19
8+
### Fixed
9+
- Pagination with null values crashes json parser (#123)
10+
711
## [5.0.4] - 2021-05-20
812
### Fixed
913
- Missing meta properties in responses
@@ -204,6 +208,7 @@ the Document model.
204208
### Added
205209
- Client: fetch resources, collections, related resources and relationships
206210

211+
[5.0.5]: https://github.com/f3ath/json-api-dart/compare/5.0.4...5.0.5
207212
[5.0.4]: https://github.com/f3ath/json-api-dart/compare/5.0.3...5.0.4
208213
[5.0.3]: https://github.com/f3ath/json-api-dart/compare/5.0.2...5.0.3
209214
[5.0.2]: https://github.com/f3ath/json-api-dart/compare/5.0.1...5.0.2

lib/src/document/inbound_document.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ class _Parser {
6767
Map<String, Object?> meta(Map json) =>
6868
json.get<Map<String, Object?>>('meta', orGet: () => {});
6969

70-
Map<String, Link> links(Map json) => json
71-
.get<Map>('links', orGet: () => {})
72-
.map((k, v) => MapEntry(k.toString(), _link(v)));
70+
Map<String, Link> links(Map json) {
71+
var links = json.get<Map>('links', orGet: () => {});
72+
links.removeWhere((key, value) => value == null);
73+
return links.map((k, v) => MapEntry(k.toString(), _link(v)));
74+
}
7375

7476
Relationship relationship(Map json) {
7577
final rel = json.containsKey('data') ? _rel(json['data']) : Relationship();

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_api
2-
version: 5.0.4
2+
version: 5.0.5
33
homepage: https://github.com/f3ath/json-api-dart
44
description: A framework-agnostic implementations of JSON:API Client and Server. Supports JSON:API v1.0 (https://jsonapi.org)
55
environment:

test/unit/document/inbound_document_test.dart

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ void main() {
7878
expect(doc.meta(), isEmpty);
7979
});
8080

81+
test('can parse the null link', () {
82+
final doc = InboundDocument(payload.nullLink);
83+
expect(doc.links()['self'].toString(), 'http://example.com/articles');
84+
expect(doc.links()['prev'], isNull);
85+
expect(doc.links()['next'], isNull);
86+
expect(doc.links()['foobar'], isNull);
87+
});
88+
8189
test('can parse primary resource', () {
8290
final doc = InboundDocument(payload.resource);
8391
final article = doc.dataAsResource();

test/unit/document/payload.dart

+9
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ final example = {
6767
]
6868
};
6969

70+
final nullLink = {
71+
'links': {
72+
'self': 'http://example.com/articles',
73+
'next': null,
74+
'last': null,
75+
},
76+
'data': []
77+
};
78+
7079
final newResource = {
7180
'data': {
7281
'type': 'articles',

0 commit comments

Comments
 (0)