Skip to content

Commit 7e46cea

Browse files
committed
Check to see if we are dealing with an object with a toJson method
- if we are dealing with something like new \Magento\Framework\DataObject() being used as a response object
1 parent 4f78388 commit 7e46cea

File tree

1 file changed

+5
-1
lines changed
  • lib/internal/Magento/Framework/Controller/Result

1 file changed

+5
-1
lines changed

lib/internal/Magento/Framework/Controller/Result/Json.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ public function __construct(
5959
*/
6060
public function setData($data, $cycleCheck = false, $options = [])
6161
{
62-
$this->json = $this->serializer->serialize($data);
62+
if (is_object($data) && method_exists($data, 'toJson')) {
63+
$this->json = $data->toJson();
64+
} else {
65+
$this->json = $this->serializer->serialize($data);
66+
}
6367
return $this;
6468
}
6569

0 commit comments

Comments
 (0)