Skip to content

Commit bf220f6

Browse files
author
GlennGeelen
committed
Fix the serialization for links
Fix all unit tests except for the filter tests
1 parent 52e5d4f commit bf220f6

8 files changed

Lines changed: 196 additions & 179 deletions

JSONAPI.Tests/Data/LinkTemplateTest.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
"data": {
33
"type": "posts",
44
"id": "2",
5-
"title": "How to fry an egg",
5+
"attributes": {
6+
"title": "How to fry an egg"
7+
},
68
"relationships": {
79
"author": {
10+
"data": {
11+
"type": "users",
12+
"id": "5"
13+
},
814
"links": {
915
"related": "/users/5"
1016
}

JSONAPI.Tests/Data/MalformedRawJsonString.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
{
44
"type": "comments",
55
"id": "5",
6-
"attributes": {
7-
"body": null
6+
"attributes": {
7+
"body": null,
8+
"customData": { }
89
},
9-
"customData": { },
1010
"relationships": {
11-
"post": null
11+
"post": {
12+
"data": null
13+
}
1214
}
1315
}
1416
]
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"data": {
3-
"type": "posts",
4-
"id": "42",
5-
"relationships": {
6-
"author": {
7-
"data": {
8-
"id": "18",
9-
"type": "authors"
10-
}
2+
"data": {
3+
"type": "posts",
4+
"id": "42",
5+
"relationships": {
6+
"author": {
7+
"data": {
8+
"type": "authors",
9+
"id": "18"
1110
}
12-
}
13-
}
11+
}
12+
}
13+
}
1414
}
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
{
2-
"data": [
3-
{
4-
"type": "comments",
5-
"id": "5",
2+
"data": [
3+
{
4+
"type": "comments",
5+
"id": "5",
6+
"attributes": {
67
"body": null,
78
"customData": {
8-
"unquotedKey": 5
9-
},
10-
"relationships": {
11-
"post": null
9+
"unquotedKey": 5
1210
}
13-
}
14-
]
11+
},
12+
"relationships": {
13+
"post": {
14+
"data": null
15+
}
16+
}
17+
}
18+
]
1519
}

JSONAPI.Tests/Data/SerializerIntegrationTest.json

Lines changed: 81 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,93 @@
11
{
2-
"data": [
3-
{
4-
"type": "posts",
5-
"id": "1",
6-
"attributes": {
7-
"title": "Linkbait!"
2+
"data": [
3+
{
4+
"type": "posts",
5+
"id": "1",
6+
"attributes": {
7+
"title": "Linkbait!"
8+
},
9+
"relationships": {
10+
"comments": {
11+
"data": [
12+
{
13+
"type": "comments",
14+
"id": "2"
15+
},
16+
{
17+
"type": "comments",
18+
"id": "3"
19+
},
20+
{
21+
"type": "comments",
22+
"id": "4"
23+
}
24+
]
825
},
9-
"relationships": {
10-
"comments": {
11-
"data": [
12-
{
13-
"type": "comments",
14-
"id": "2"
15-
},
16-
{
17-
"type": "comments",
18-
"id": "3"
19-
},
20-
{
21-
"type": "comments",
22-
"id": "4"
23-
}
24-
]
25-
},
26-
"author": {
27-
"data": {
28-
"type": "authors",
29-
"id": "1"
30-
}
31-
}
26+
"author": {
27+
"data": {
28+
"type": "authors",
29+
"id": "1"
30+
}
3231
}
33-
},
34-
{
35-
"type": "posts",
36-
"id": "2",
37-
"attributes": {
38-
"title": "Rant #1023"
32+
}
33+
},
34+
{
35+
"type": "posts",
36+
"id": "2",
37+
"attributes": {
38+
"title": "Rant #1023"
39+
},
40+
"relationships": {
41+
"comments": {
42+
"data": [
43+
{
44+
"type": "comments",
45+
"id": "5"
46+
}
47+
]
3948
},
40-
"relationships": {
41-
"comments": {
42-
"data": [
43-
{
44-
"type": "comments",
45-
"id": "5"
46-
}
47-
]
48-
},
49-
"author": {
50-
"data": {
51-
"type": "authors",
52-
"id": "1"
53-
}
54-
}
49+
"author": {
50+
"data": {
51+
"type": "authors",
52+
"id": "1"
53+
}
5554
}
56-
},
57-
{
58-
"type": "posts",
59-
"id": "3",
60-
"attributes": {
61-
"title": "Polemic in E-flat minor #824"
55+
}
56+
},
57+
{
58+
"type": "posts",
59+
"id": "3",
60+
"attributes": {
61+
"title": "Polemic in E-flat minor #824"
62+
},
63+
"relationships": {
64+
"comments": {
65+
"data": [ ]
6266
},
63-
"relationships": {
64-
"comments": [ ],
65-
"author": {
66-
"data": {
67-
"type": "authors",
68-
"id": "1"
69-
}
70-
}
67+
"author": {
68+
"data": {
69+
"type": "authors",
70+
"id": "1"
71+
}
7172
}
72-
},
73-
{
74-
"type": "posts",
75-
"id": "4",
76-
"attributes": {
77-
"title": "This post has no author."
73+
}
74+
},
75+
{
76+
"type": "posts",
77+
"id": "4",
78+
"attributes": {
79+
"title": "This post has no author."
80+
},
81+
"relationships": {
82+
"comments": {
83+
"data": [ ]
7884
},
79-
"relationships": {
80-
"comments": [ ],
81-
"author": null
85+
"author": {
86+
"data": null
8287
}
83-
}
84-
],
88+
}
89+
}
90+
],
8591
"included": [
8692
{
8793
"type": "comments",

JSONAPI.Tests/Json/LinkTemplateTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private class Post
1717

1818
public string Title { get; set; }
1919

20-
[SerializeAs(SerializeAsOptions.Link)]
20+
[SerializeAs(SerializeAsOptions.RelatedLink)]
2121
[LinkTemplate("/users/{0}")]
2222
public virtual User Author { get; set; }
2323
}

JSONAPI/Attributes/SerializeAs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace JSONAPI.Attributes
44
{
5-
public enum SerializeAsOptions { Ids, Link }
5+
public enum SerializeAsOptions { RelatedLink, SelfLink, BothLinks, NoLinks }
66

77
[System.AttributeUsage(System.AttributeTargets.Property)]
88
public class SerializeAs

0 commit comments

Comments
 (0)