-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Manage php JsonSerializable #13496
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
Comments
The ObjectNormalizer (#13257) is a good candidate to implement this feature. However, I cannot see a way yo make it compliant with serialization groups and how to handle deserialization support. |
This is an excellent suggestion. In an API for example, every "returnable" object could provides its own Json representation. |
@hatembr what did you use/do instead? |
For now, in one of the projects I am working on, I had ti use a simple an basic solution. I had to build my own classes that managed the API responses in JSON format. |
Why not implement a normalizer for this? Something like https://gist.github.com/boekkooi/5a7d59981739fa0ea5f0 |
Yes it can be done that way. Groups can even be supported (iterate over the resulting array and remove keys not in applicable groups). Do you want to work on a PR? |
I wish I had the time to work on this but I'm sorry to say that I really don't have the time. |
…zable objects (mcfedr) This PR was merged into the 3.1-dev branch. Discussion ---------- [Serializer] Add a normalizer that support JsonSerializable objects This normalizer makes it easier to start to combine using `JsonSerializable` objects with the Symfony serializer. I have implemented it in a number of projects and #13496 shows that others are doing so as well. So it seemed like it would be useful to include it in the Serializer component. It handles circular references in the same way as the other normalizers. Because groups and max depth are based on property annotations it doesn't make sense to apply them here. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #13496 | License | MIT | Doc PR | Commits ------- a678881 Add a normalizer that support JsonSerializable objects
As it's a great enhancement from
php 5.4
: http://php.net/manual/en/class.jsonserializable.php should be cool the Serializer component would manage objects that implement this interface. Thoughts?The text was updated successfully, but these errors were encountered: