Skip to content

Links with null values #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/src/document/inbound_document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ class _Parser {
Map<String, Object?> meta(Map json) =>
json.get<Map<String, Object?>>('meta', orGet: () => {});

Map<String, Link> links(Map json) => json
.get<Map>('links', orGet: () => {})
.map((k, v) => MapEntry(k.toString(), _link(v)));
Map<String, Link> links(Map json) {
var links = json.get<Map>('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();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
8 changes: 8 additions & 0 deletions test/unit/document/inbound_document_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions test/unit/document/payload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ final example = {
]
};

final nullLink = {
'links': {
'self': 'http://example.com/articles',
'next': null,
'last': null,
},
'data': []
};

final newResource = {
'data': {
'type': 'articles',
Expand Down