FOSElastica why my result is not serialized? FOSElastica why my result is not serialized? elasticsearch elasticsearch

FOSElastica why my result is not serialized?


You do not understand documentation. As you can read in the following file:https://github.com/FriendsOfSymfony/FOSElasticaBundle/blob/master/Resources/doc/serializer.md

FOSElasticaBundle supports using a Serializer component to serialize your objects to JSON which will be sent directly to the Elasticsearch server. Combined with automatic mapping it means types do not have to be mapped.

FOSElasticaBundle does not return serialized data. It uses serialzier to send serialized data to elasticsearch server. When using serializer you do not have to provide mapping in your config.


AppBundle\Entity\Tag should implement \JsonSerializable interface so Elastica will handle it grafefully. Some discussions regarding this topic were here: https://github.com/ruflin/Elastica/issues/783


There is a problem with serialize $results to json with JsonResponse.

JsonResponse class is doing simple json_encode inside, so there is no chance to get protected properties.

For example:

<?phpclass Data {protected $id = 1;public $name = 'foo';}var_dump(json_encode(new Data()));

returns {"name":"foo"}