mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Doctrine does not have a method to convert entities to JSON #6814
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 @ghost on GitHub (Sep 1, 2021).
Feature Request
Summary
This feature is EXTREMELY basic and the whole doctrine ORM is basically useless if you are unable to convert entities (select query results, etc) into json for returning in an API. Either the feature doesn't exist, which is honestly unbelievable, or there is a desperate need to add documentation for it, since not even stackoverflow requests have come to any reasonable conclusion in the past 10 years.
@derrabus commented on GitHub (Sep 1, 2021):
Thank you for your friendly request. The feature that you're looking for is called
json_encode(), see https://www.php.net/json_encodeIf you need more sophisticated serialization solutions, there's Symfony Serializer, JMS Serializer and other high quality open source libraries. I don't think that Doctrine has to invent its own solution.
@ghost commented on GitHub (Sep 1, 2021):
@derrabus I don't see anywhere stated that, say, the Symfony serializer or JMS Serializer provides support for Doctrine. Notice that serialization of Doctrine Entities might lead to infinite recursion because of associations. Every ORM I have ever used throughout 10 years of web development career provide serialization methods because of this very issue. It is important to have a serializer that provides support for Doctrine, not merely a generic serializer. Or are Doctrine entities, query results, etc, with associations ready to be blindly serialized?
@derrabus commented on GitHub (Sep 1, 2021):
The solutions I've provided you with are used quite commonly for serializing entity models hydrated with Doctrine ORM. Give them a try.
@ghost commented on GitHub (Sep 1, 2021):
@derrabus To use the JMS Serializer Bundle in Symfony, I need to access the "$container" variable in Symfony controllers, which there is no documentation about how to access that variable. There is no minimal documentation about how to use the JMS Serializer Bundle. Please notice that json serialization is an EXTREMELY BASIC feature, and it is not minimally documented anywhere.
@derrabus commented on GitHub (Sep 1, 2021):
As mentioned on symfony/symfony#42833, use Symfony's discussions for support on Symfony.
https://github.com/symfony/symfony/discussions