File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
src/Implementation/Encoding Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,15 @@ public function encode(ResourceInterface $resource): array
59
59
}
60
60
61
61
if (null !== $ resource ->getRelationships ()) {
62
- $ serializedResource ['relationships ' ] = $ this ->relationshipCollectionEncoder ->encode ($ resource ->getRelationships ());
62
+ $ encodedRelationships = $ this ->relationshipCollectionEncoder ->encode ($ resource ->getRelationships ());
63
+ // relationships key must be object
64
+ // if it's empty, we'll get empty array and it will be encoded to array
65
+ // so in that case we'll create php object so json encode will return object
66
+ if (true === empty ($ encodedRelationships )) {
67
+ $ encodedRelationships = new \stdClass ();
68
+ }
69
+
70
+ $ serializedResource ['relationships ' ] = $ encodedRelationships ;
63
71
}
64
72
65
73
return $ serializedResource ;
You can’t perform that action at this time.
0 commit comments