Skip to content

Commit 75b490f

Browse files
authored
Fix #54 (#55)
1 parent 5cf69f4 commit 75b490f

File tree

5 files changed

+110
-5
lines changed

5 files changed

+110
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.0.2] - 2019-08-01
10+
### Fixed
11+
- Meta members have incorrect type ([#54](https://github.com/f3ath/json-api-dart/issues/54))
12+
913
## [2.0.1] - 2019-07-12
1014
### Fixed
1115
- Readme example is outdated
@@ -81,7 +85,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8185
### Added
8286
- Client: fetch resources, collections, related resources and relationships
8387

84-
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/2.0.1...HEAD
88+
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/2.0.2...HEAD
89+
[2.0.2]: https://github.com/f3ath/json-api-dart/compare/2.0.1...2.0.2
8590
[2.0.1]: https://github.com/f3ath/json-api-dart/compare/2.0.0...2.0.1
8691
[2.0.0]: https://github.com/f3ath/json-api-dart/compare/1.0.1...2.0.0
8792
[1.0.1]: https://github.com/f3ath/json-api-dart/compare/1.0.0...1.0.1

lib/src/document/identifier_object.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class IdentifierObject {
77
final String type;
88
final String id;
99

10-
final Map<String, String> meta;
10+
final Map<String, Object> meta;
1111

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

lib/src/document/resource_object.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ResourceObject {
1818
final Link self;
1919
final Map<String, Object> attributes;
2020
final Map<String, Relationship> relationships;
21-
final Map<String, String> meta;
21+
final Map<String, Object> meta;
2222

2323
ResourceObject(this.type, this.id,
2424
{this.self,
@@ -40,7 +40,8 @@ class ResourceObject {
4040
return ResourceObject(json['type'], json['id'],
4141
attributes: attributes,
4242
relationships: Relationship.decodeJsonMap(relationships),
43-
self: links['self']);
43+
self: links['self'],
44+
meta: json['meta']);
4445
}
4546
}
4647
throw DecodingException('Can not decode ResourceObject from $json');

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ author: "Alexey Karapetov <karapetov@gmail.com>"
22
description: "JSON:API Client for Flutter, Web and VM. Supports JSON:API v1.0 (http://jsonapi.org)"
33
homepage: "https://github.com/f3ath/json-api-dart"
44
name: "json_api"
5-
version: "2.0.1+1"
5+
version: "2.0.2"
66
dependencies:
77
collection: "^1.14.11"
88
http: "^0.12.0"
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import 'package:json_api/document.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
group('Meta members', () {
6+
test('should be parsed correctly', () {
7+
final meta = {
8+
"bool": true,
9+
"array": [1, 2, 3],
10+
"string": "foo"
11+
};
12+
final json = {
13+
"links": {
14+
"self": "http://example.com/articles",
15+
"next": "http://example.com/articles?page=2",
16+
"last": "http://example.com/articles?page=10"
17+
},
18+
"meta": meta,
19+
"data": [
20+
{
21+
"type": "articles",
22+
"id": "1",
23+
"attributes": {"title": "JSON:API paints my bikeshed!"},
24+
"meta": meta,
25+
"relationships": {
26+
"author": {
27+
"links": {
28+
"self": "http://example.com/articles/1/relationships/author",
29+
"related": "http://example.com/articles/1/author"
30+
},
31+
"data": {"type": "people", "id": "9"}
32+
},
33+
"comments": {
34+
"links": {
35+
"self":
36+
"http://example.com/articles/1/relationships/comments",
37+
"related": "http://example.com/articles/1/comments"
38+
},
39+
"data": [
40+
{
41+
"type": "comments",
42+
"id": "5",
43+
"meta": meta,
44+
},
45+
{"type": "comments", "id": "12"}
46+
]
47+
}
48+
},
49+
"links": {"self": "http://example.com/articles/1"}
50+
}
51+
],
52+
"included": [
53+
{
54+
"type": "people",
55+
"id": "9",
56+
"attributes": {
57+
"firstName": "Dan",
58+
"lastName": "Gebhardt",
59+
"twitter": "dgeb"
60+
},
61+
"links": {"self": "http://example.com/people/9"}
62+
},
63+
{
64+
"type": "comments",
65+
"id": "5",
66+
"attributes": {"body": "First!"},
67+
"relationships": {
68+
"author": {
69+
"data": {"type": "people", "id": "2"}
70+
}
71+
},
72+
"links": {"self": "http://example.com/comments/5"}
73+
},
74+
{
75+
"type": "comments",
76+
"id": "12",
77+
"attributes": {"body": "I like XML better"},
78+
"relationships": {
79+
"author": {
80+
"data": {"type": "people", "id": "9"}
81+
}
82+
},
83+
"links": {"self": "http://example.com/comments/12"}
84+
}
85+
]
86+
};
87+
88+
final doc = Document.decodeJson(json, ResourceCollectionData.decodeJson);
89+
expect(doc.meta["bool"], true);
90+
expect(doc.data.collection.first.meta, meta);
91+
expect(
92+
(doc.data.collection.first.relationships['comments'] as ToMany)
93+
.linkage
94+
.first
95+
.meta,
96+
meta);
97+
});
98+
});
99+
}

0 commit comments

Comments
 (0)