diff --git a/CHANGELOG.md b/CHANGELOG.md index d6b1b19..89a17ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [5.0.5] - 2021-07-19 +### Fixed +- Pagination with null values crashes json parser (#123) + ## [5.0.4] - 2021-05-20 ### Fixed - Missing meta properties in responses @@ -204,6 +208,7 @@ the Document model. ### Added - Client: fetch resources, collections, related resources and relationships +[5.0.5]: https://github.com/f3ath/json-api-dart/compare/5.0.4...5.0.5 [5.0.4]: https://github.com/f3ath/json-api-dart/compare/5.0.3...5.0.4 [5.0.3]: https://github.com/f3ath/json-api-dart/compare/5.0.2...5.0.3 [5.0.2]: https://github.com/f3ath/json-api-dart/compare/5.0.1...5.0.2 diff --git a/lib/src/document/inbound_document.dart b/lib/src/document/inbound_document.dart index 1c16952..2d5b30a 100644 --- a/lib/src/document/inbound_document.dart +++ b/lib/src/document/inbound_document.dart @@ -67,9 +67,11 @@ class _Parser { Map meta(Map json) => json.get>('meta', orGet: () => {}); - Map links(Map json) => json - .get('links', orGet: () => {}) - .map((k, v) => MapEntry(k.toString(), _link(v))); + Map links(Map json) { + var links = json.get('links', orGet: () => {}); + links.removeWhere((key, value) => value == null); + return links.map((k, v) => MapEntry(k.toString(), _link(v))); + } Relationship relationship(Map json) { final rel = json.containsKey('data') ? _rel(json['data']) : Relationship(); diff --git a/pubspec.yaml b/pubspec.yaml index 5d81ba9..f875176 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: json_api -version: 5.0.4 +version: 5.0.5 homepage: https://github.com/f3ath/json-api-dart description: A framework-agnostic implementations of JSON:API Client and Server. Supports JSON:API v1.0 (https://jsonapi.org) environment: diff --git a/test/unit/document/inbound_document_test.dart b/test/unit/document/inbound_document_test.dart index 7566943..0123e38 100644 --- a/test/unit/document/inbound_document_test.dart +++ b/test/unit/document/inbound_document_test.dart @@ -78,6 +78,14 @@ void main() { expect(doc.meta(), isEmpty); }); + test('can parse the null link', () { + final doc = InboundDocument(payload.nullLink); + expect(doc.links()['self'].toString(), 'http://example.com/articles'); + expect(doc.links()['prev'], isNull); + expect(doc.links()['next'], isNull); + expect(doc.links()['foobar'], isNull); + }); + test('can parse primary resource', () { final doc = InboundDocument(payload.resource); final article = doc.dataAsResource(); diff --git a/test/unit/document/payload.dart b/test/unit/document/payload.dart index fc1758c..c7d6cb0 100644 --- a/test/unit/document/payload.dart +++ b/test/unit/document/payload.dart @@ -67,6 +67,15 @@ final example = { ] }; +final nullLink = { + 'links': { + 'self': 'http://example.com/articles', + 'next': null, + 'last': null, + }, + 'data': [] +}; + final newResource = { 'data': { 'type': 'articles',