Skip to content

Commit abf26c4

Browse files
authored
Address #102 (#103)
1 parent 71d9e6c commit abf26c4

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

CHANGELOG.md

+14-9
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [4.2.2] - 2020-06-05
10+
### Fixed
11+
- Client throws NoSuchMethodError on unexpected primary data ([issue](https://github.com/f3ath/json-api-dart/issues/102)).
12+
913
## [4.2.1] - 2020-06-04
1014
### Fixed
1115
- The server library was not exporting `Controller`.
1216
- `ResourceData.toJson()` was not calling the underlying `ResourceObject.toJson()`.
1317

1418
## [4.2.0] - 2020-06-03
1519
### Added
16-
- Filtering support for collections ([#97](https://github.com/f3ath/json-api-dart/pull/97))
20+
- Filtering support for collections ([pr](https://github.com/f3ath/json-api-dart/pull/97))
1721

1822
### Changed
1923
- The client will not attempt to decode the body of the HTTP response with error status if the correct Content-Type
20-
is missing. Before in such cases a `FormatException` would be thrown ([#98](https://github.com/f3ath/json-api-dart/pull/98))
24+
is missing. Before in such cases a `FormatException` would be thrown ([pr](https://github.com/f3ath/json-api-dart/pull/98))
2125

2226
## [4.1.0] - 2020-05-28
2327
### Changed
@@ -29,11 +33,11 @@ is missing. Before in such cases a `FormatException` would be thrown ([#98](http
2933

3034
## [3.2.2] - 2020-01-07
3135
### Fixed
32-
- Can not decode related resource which is null ([#77](https://github.com/f3ath/json-api-dart/issues/77))
36+
- Can not decode related resource which is null ([issue](https://github.com/f3ath/json-api-dart/issues/77))
3337

3438
## [3.2.1] - 2020-01-01
3539
### Fixed
36-
- Incorrect URL in the example in the Client documentation ([#74](https://github.com/f3ath/json-api-dart/issues/74))
40+
- Incorrect URL in the example in the Client documentation ([issue](https://github.com/f3ath/json-api-dart/issues/74))
3741

3842
## [3.2.0] - 2019-12-30
3943
### Added
@@ -59,7 +63,7 @@ is missing. Before in such cases a `FormatException` would be thrown ([#98](http
5963

6064
## [3.0.0] - 2019-12-17
6165
### Added
62-
- Support for custom non-standard links ([#61](https://github.com/f3ath/json-api-dart/issues/61))
66+
- Support for custom non-standard links ([issue](https://github.com/f3ath/json-api-dart/issues/61))
6367
- Client supports `jsonapi` key in outgoing requests.
6468
- `Document.contentType` constant.
6569
- `IdentifierObject.fromIdentifier` factory method
@@ -84,15 +88,15 @@ Most of the changes are **BC-BREAKING**.
8488

8589
## [2.1.0] - 2019-12-04
8690
### Added
87-
- `onHttpCall` hook to enable raw http request/response logging ([#60](https://github.com/f3ath/json-api-dart/issues/60)).
91+
- `onHttpCall` hook to enable raw http request/response logging ([issue](https://github.com/f3ath/json-api-dart/issues/60)).
8892

8993
## [2.0.3] - 2019-09-29
9094
### Fixed
9195
- Documentation links got broken due to pub.dev update.
9296

9397
## [2.0.2] - 2019-08-01
9498
### Fixed
95-
- Meta members have incorrect type ([#54](https://github.com/f3ath/json-api-dart/issues/54)).
99+
- Meta members have incorrect type ([issue](https://github.com/f3ath/json-api-dart/issues/54)).
96100

97101
## [2.0.1] - 2019-07-12
98102
### Fixed
@@ -133,7 +137,7 @@ Most of the changes are **BC-BREAKING**.
133137
- More BC-breaking changes in the Server
134138

135139
### Fixed
136-
- Location headers were incorrectly generated by Server
140+
- Location headers generated incorrectly
137141

138142
### Added
139143
- Related collection pagination
@@ -169,7 +173,8 @@ Most of the changes are **BC-BREAKING**.
169173
### Added
170174
- Client: fetch resources, collections, related resources and relationships
171175

172-
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/4.2.1...HEAD
176+
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/4.2.2...HEAD
177+
[4.2.2]: https://github.com/f3ath/json-api-dart/compare/4.2.1...4.2.2
173178
[4.2.1]: https://github.com/f3ath/json-api-dart/compare/4.2.0...4.2.1
174179
[4.2.0]: https://github.com/f3ath/json-api-dart/compare/4.1.0...4.2.0
175180
[4.1.0]: https://github.com/f3ath/json-api-dart/compare/4.0.0...4.1.0

lib/src/document/document.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Document<Data extends PrimaryData> implements JsonEncodable {
6666
return Document.error(errors.map(ErrorObject.fromJson),
6767
meta: json['meta'], api: api);
6868
}
69-
} else if (json.containsKey('data')) {
69+
} else if (primaryData != null) {
7070
return Document(primaryData(json), meta: json['meta'], api: api);
7171
} else if (json['meta'] != null) {
7272
return Document.empty(json['meta'], api: api);

pubspec.yaml

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

test/unit/client/non_json_response_test.dart renamed to test/unit/client/conrner_cases_test.dart

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:convert';
2+
13
import 'package:json_api/client.dart';
24
import 'package:json_api/http.dart';
35
import 'package:json_api/routing.dart';
@@ -8,7 +10,7 @@ import '../../helper/test_http_handler.dart';
810
void main() {
911
final handler = TestHttpHandler();
1012
final client = RoutingClient(JsonApiClient(handler), StandardRouting());
11-
test('Error status code with incorrect content-type is not decoded',
13+
test('Error status code with incorrect content-type, body is not decoded',
1214
() async {
1315
handler.nextResponse = HttpResponse(500, body: 'Something went wrong');
1416

@@ -20,4 +22,21 @@ void main() {
2022
expect(r.asyncData, isNull);
2123
expect(r.statusCode, 500);
2224
});
25+
26+
test('Do not attempt to decode primary data if decoder is null', () async {
27+
handler.nextResponse = HttpResponse(200,
28+
body: jsonEncode({
29+
'meta': {'foo': 'bar'},
30+
'data': {'id': '123', 'type': 'books'}
31+
}));
32+
33+
final r = await client.deleteResource('books', '123');
34+
expect(r.isAsync, false);
35+
expect(r.isSuccessful, true);
36+
expect(r.isFailed, false);
37+
expect(r.data, isNull);
38+
expect(r.document.meta['foo'], 'bar');
39+
expect(r.asyncData, isNull);
40+
expect(r.statusCode, 200);
41+
});
2342
}

test/unit/document/document_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:test/test.dart';
33

44
void main() {
55
test('Unrecognized structure', () {
6-
expect(() => Document.fromJson({}, ResourceData.fromJson),
6+
expect(() => Document.fromJson({}, ResourceCollectionData.fromJson),
77
throwsA(TypeMatcher<DocumentException>()));
88
});
99
}

0 commit comments

Comments
 (0)