Skip to content

Commit

Permalink
Fix #54 (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath committed Aug 1, 2019
1 parent 5cf69f4 commit 75b490f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

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

## [2.0.1] - 2019-07-12
### Fixed
- Readme example is outdated
Expand Down Expand Up @@ -81,7 +85,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Client: fetch resources, collections, related resources and relationships

[Unreleased]: https://github.com/f3ath/json-api-dart/compare/2.0.1...HEAD
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/2.0.2...HEAD
[2.0.2]: https://github.com/f3ath/json-api-dart/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/f3ath/json-api-dart/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/f3ath/json-api-dart/compare/1.0.1...2.0.0
[1.0.1]: https://github.com/f3ath/json-api-dart/compare/1.0.0...1.0.1
Expand Down
2 changes: 1 addition & 1 deletion lib/src/document/identifier_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class IdentifierObject {
final String type;
final String id;

final Map<String, String> meta;
final Map<String, Object> meta;

IdentifierObject(this.type, this.id, {this.meta});

Expand Down
5 changes: 3 additions & 2 deletions lib/src/document/resource_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ResourceObject {
final Link self;
final Map<String, Object> attributes;
final Map<String, Relationship> relationships;
final Map<String, String> meta;
final Map<String, Object> meta;

ResourceObject(this.type, this.id,
{this.self,
Expand All @@ -40,7 +40,8 @@ class ResourceObject {
return ResourceObject(json['type'], json['id'],
attributes: attributes,
relationships: Relationship.decodeJsonMap(relationships),
self: links['self']);
self: links['self'],
meta: json['meta']);
}
}
throw DecodingException('Can not decode ResourceObject from $json');
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ author: "Alexey Karapetov <karapetov@gmail.com>"
description: "JSON:API Client for Flutter, Web and VM. Supports JSON:API v1.0 (http://jsonapi.org)"
homepage: "https://github.com/f3ath/json-api-dart"
name: "json_api"
version: "2.0.1+1"
version: "2.0.2"
dependencies:
collection: "^1.14.11"
http: "^0.12.0"
Expand Down
99 changes: 99 additions & 0 deletions test/unit/document/meta_members_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import 'package:json_api/document.dart';
import 'package:test/test.dart';

void main() {
group('Meta members', () {
test('should be parsed correctly', () {
final meta = {
"bool": true,
"array": [1, 2, 3],
"string": "foo"
};
final json = {
"links": {
"self": "http://example.com/articles",
"next": "http://example.com/articles?page=2",
"last": "http://example.com/articles?page=10"
},
"meta": meta,
"data": [
{
"type": "articles",
"id": "1",
"attributes": {"title": "JSON:API paints my bikeshed!"},
"meta": meta,
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
},
"data": {"type": "people", "id": "9"}
},
"comments": {
"links": {
"self":
"http://example.com/articles/1/relationships/comments",
"related": "http://example.com/articles/1/comments"
},
"data": [
{
"type": "comments",
"id": "5",
"meta": meta,
},
{"type": "comments", "id": "12"}
]
}
},
"links": {"self": "http://example.com/articles/1"}
}
],
"included": [
{
"type": "people",
"id": "9",
"attributes": {
"firstName": "Dan",
"lastName": "Gebhardt",
"twitter": "dgeb"
},
"links": {"self": "http://example.com/people/9"}
},
{
"type": "comments",
"id": "5",
"attributes": {"body": "First!"},
"relationships": {
"author": {
"data": {"type": "people", "id": "2"}
}
},
"links": {"self": "http://example.com/comments/5"}
},
{
"type": "comments",
"id": "12",
"attributes": {"body": "I like XML better"},
"relationships": {
"author": {
"data": {"type": "people", "id": "9"}
}
},
"links": {"self": "http://example.com/comments/12"}
}
]
};

final doc = Document.decodeJson(json, ResourceCollectionData.decodeJson);
expect(doc.meta["bool"], true);
expect(doc.data.collection.first.meta, meta);
expect(
(doc.data.collection.first.relationships['comments'] as ToMany)
.linkage
.first
.meta,
meta);
});
});
}

0 comments on commit 75b490f

Please sign in to comment.