diff --git a/CHANGELOG.md b/CHANGELOG.md index 73c9e6c..acecda5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [4.2.2] - 2020-06-05 +### Fixed +- Client throws NoSuchMethodError on unexpected primary data ([issue](https://github.com/f3ath/json-api-dart/issues/102)). + ## [4.2.1] - 2020-06-04 ### Fixed - The server library was not exporting `Controller`. @@ -13,11 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [4.2.0] - 2020-06-03 ### Added -- Filtering support for collections ([#97](https://github.com/f3ath/json-api-dart/pull/97)) +- Filtering support for collections ([pr](https://github.com/f3ath/json-api-dart/pull/97)) ### Changed - The client will not attempt to decode the body of the HTTP response with error status if the correct Content-Type -is missing. Before in such cases a `FormatException` would be thrown ([#98](https://github.com/f3ath/json-api-dart/pull/98)) +is missing. Before in such cases a `FormatException` would be thrown ([pr](https://github.com/f3ath/json-api-dart/pull/98)) ## [4.1.0] - 2020-05-28 ### Changed @@ -29,11 +33,11 @@ is missing. Before in such cases a `FormatException` would be thrown ([#98](http ## [3.2.2] - 2020-01-07 ### Fixed -- Can not decode related resource which is null ([#77](https://github.com/f3ath/json-api-dart/issues/77)) +- Can not decode related resource which is null ([issue](https://github.com/f3ath/json-api-dart/issues/77)) ## [3.2.1] - 2020-01-01 ### Fixed -- Incorrect URL in the example in the Client documentation ([#74](https://github.com/f3ath/json-api-dart/issues/74)) +- Incorrect URL in the example in the Client documentation ([issue](https://github.com/f3ath/json-api-dart/issues/74)) ## [3.2.0] - 2019-12-30 ### Added @@ -59,7 +63,7 @@ is missing. Before in such cases a `FormatException` would be thrown ([#98](http ## [3.0.0] - 2019-12-17 ### Added -- Support for custom non-standard links ([#61](https://github.com/f3ath/json-api-dart/issues/61)) +- Support for custom non-standard links ([issue](https://github.com/f3ath/json-api-dart/issues/61)) - Client supports `jsonapi` key in outgoing requests. - `Document.contentType` constant. - `IdentifierObject.fromIdentifier` factory method @@ -84,7 +88,7 @@ Most of the changes are **BC-BREAKING**. ## [2.1.0] - 2019-12-04 ### Added -- `onHttpCall` hook to enable raw http request/response logging ([#60](https://github.com/f3ath/json-api-dart/issues/60)). +- `onHttpCall` hook to enable raw http request/response logging ([issue](https://github.com/f3ath/json-api-dart/issues/60)). ## [2.0.3] - 2019-09-29 ### Fixed @@ -92,7 +96,7 @@ Most of the changes are **BC-BREAKING**. ## [2.0.2] - 2019-08-01 ### Fixed -- Meta members have incorrect type ([#54](https://github.com/f3ath/json-api-dart/issues/54)). +- Meta members have incorrect type ([issue](https://github.com/f3ath/json-api-dart/issues/54)). ## [2.0.1] - 2019-07-12 ### Fixed @@ -133,7 +137,7 @@ Most of the changes are **BC-BREAKING**. - More BC-breaking changes in the Server ### Fixed -- Location headers were incorrectly generated by Server +- Location headers generated incorrectly ### Added - Related collection pagination @@ -169,7 +173,8 @@ Most of the changes are **BC-BREAKING**. ### Added - Client: fetch resources, collections, related resources and relationships -[Unreleased]: https://github.com/f3ath/json-api-dart/compare/4.2.1...HEAD +[Unreleased]: https://github.com/f3ath/json-api-dart/compare/4.2.2...HEAD +[4.2.2]: https://github.com/f3ath/json-api-dart/compare/4.2.1...4.2.2 [4.2.1]: https://github.com/f3ath/json-api-dart/compare/4.2.0...4.2.1 [4.2.0]: https://github.com/f3ath/json-api-dart/compare/4.1.0...4.2.0 [4.1.0]: https://github.com/f3ath/json-api-dart/compare/4.0.0...4.1.0 diff --git a/lib/src/document/document.dart b/lib/src/document/document.dart index 50bab9f..2d7e9ba 100644 --- a/lib/src/document/document.dart +++ b/lib/src/document/document.dart @@ -66,7 +66,7 @@ class Document implements JsonEncodable { return Document.error(errors.map(ErrorObject.fromJson), meta: json['meta'], api: api); } - } else if (json.containsKey('data')) { + } else if (primaryData != null) { return Document(primaryData(json), meta: json['meta'], api: api); } else if (json['meta'] != null) { return Document.empty(json['meta'], api: api); diff --git a/pubspec.yaml b/pubspec.yaml index 4177f12..99a965b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: json_api -version: 4.2.1 +version: 4.2.2 homepage: https://github.com/f3ath/json-api-dart description: Framework-agnostic implementations of JSON:API Client (Flutter, Web and VM) and Server (VM). Supports JSON:API v1.0 (http://jsonapi.org) environment: diff --git a/test/unit/client/non_json_response_test.dart b/test/unit/client/conrner_cases_test.dart similarity index 50% rename from test/unit/client/non_json_response_test.dart rename to test/unit/client/conrner_cases_test.dart index 15d7896..5ca311f 100644 --- a/test/unit/client/non_json_response_test.dart +++ b/test/unit/client/conrner_cases_test.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:json_api/client.dart'; import 'package:json_api/http.dart'; import 'package:json_api/routing.dart'; @@ -8,7 +10,7 @@ import '../../helper/test_http_handler.dart'; void main() { final handler = TestHttpHandler(); final client = RoutingClient(JsonApiClient(handler), StandardRouting()); - test('Error status code with incorrect content-type is not decoded', + test('Error status code with incorrect content-type, body is not decoded', () async { handler.nextResponse = HttpResponse(500, body: 'Something went wrong'); @@ -20,4 +22,21 @@ void main() { expect(r.asyncData, isNull); expect(r.statusCode, 500); }); + + test('Do not attempt to decode primary data if decoder is null', () async { + handler.nextResponse = HttpResponse(200, + body: jsonEncode({ + 'meta': {'foo': 'bar'}, + 'data': {'id': '123', 'type': 'books'} + })); + + final r = await client.deleteResource('books', '123'); + expect(r.isAsync, false); + expect(r.isSuccessful, true); + expect(r.isFailed, false); + expect(r.data, isNull); + expect(r.document.meta['foo'], 'bar'); + expect(r.asyncData, isNull); + expect(r.statusCode, 200); + }); } diff --git a/test/unit/document/document_test.dart b/test/unit/document/document_test.dart index 5dc2b45..e094c72 100644 --- a/test/unit/document/document_test.dart +++ b/test/unit/document/document_test.dart @@ -3,7 +3,7 @@ import 'package:test/test.dart'; void main() { test('Unrecognized structure', () { - expect(() => Document.fromJson({}, ResourceData.fromJson), + expect(() => Document.fromJson({}, ResourceCollectionData.fromJson), throwsA(TypeMatcher())); }); }