mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-3183: Add JsonSerializable to Collections #3944
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jun 22, 2014).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user gabrielbull:
Implement this:
http://www.php.net/manual/fr/class.jsonserializable.php
Can't really make this claim if Doctrine is not implementing basic interfaces for collections:
@Richard87 commented on GitHub (Jan 6, 2016):
I also would like this, would make some use-cases slightly simpler :) Also, as far as I can imagine, all that is needed is this function in
ArrayCollection:Obvously this would require all elements in the array to also be json serializable... Should I try to create a pull-request for this, and if so, add it sooner that v. 3?
@Ocramius commented on GitHub (Jan 6, 2016):
This is a basic SRP violation. Serialization (into JSON in this case) is out of the scope of the ORM, and also of the entire doctrine project at the moment.
@Richard87 commented on GitHub (Jan 6, 2016):
I see your point, but
ArrayCollectionis not a part of ORM(?)... And as GabrielBull commented, that it belongs in a object that seeks to replace PHPs array?@Ocramius commented on GitHub (Jan 6, 2016):
The doctrine collections library abstracts reading/writing of elements in a collection-alike structure: it doesn't abstract transforming the collection into something else (SRP still applies).
It is trivial to simply call
toArrayon a collection inside an entity'sJsonSerializableimplementation.@Richard87 commented on GitHub (Jan 6, 2016):
Yeah, thats true... thanks for the explanation :)