예제 #1
0
 /**
  * @param NQLQuery $nqlQuery
  * @param bool $skipSelection
  *
  * @return mixed|string
  * @throws \Trinity\Bundle\SearchBundle\Exception\SyntaxErrorException
  */
 public function convertToJson(NQLQuery $nqlQuery, bool $skipSelection)
 {
     $entities = $nqlQuery->getQueryBuilder($skipSelection)->getQuery()->getResult();
     if (!$skipSelection) {
         return SerializerBuilder::create()->setPropertyNamingStrategy(new SerializedNameAnnotationStrategy(new PassThroughNamingStrategy()))->build()->serialize($entities, 'json');
     }
     $result = [];
     /** @var Select $select */
     $select = $nqlQuery->getSelect();
     foreach ($entities as $entity) {
         $result[] = $this->select($select->getColumns(), $entity);
     }
     $context = new SerializationContext();
     $context->setSerializeNull(true);
     return SerializerBuilder::create()->setPropertyNamingStrategy(new SerializedNameAnnotationStrategy(new PassThroughNamingStrategy()))->build()->serialize($result, 'json', $context);
 }