Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media::encode() causes $data objects that implement JsonSerializer to json_encode incorrectly. #1154

Open
adallaway opened this issue Dec 12, 2014 · 1 comment

Comments

@adallaway
Copy link

Media::encode() casts objects in the view data to arrays.
This prevents jsonSerialize() from being called on objects that implement JsonSerializable.

I'm not sure if this is intended behavior but here's a possible fix:
https://github.com/UnionOfRAD/lithium/blob/master/net/http/Media.php#L766

if ($data instanceof \JsonSerializable)) {
  return $data;
}

As a workaround, a dummy to() method can be added to the objects:

public function to()
{
  return $this;
}
@mariuswilms
Copy link
Member

Until we find a clean solution for this, try reregistering the json handler with 'cast' set to false. That only works if you always hand JsonSerializable objects to the view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants