jmsserializerbundle

symfony2: JMSSerializerBundle changes the attribute name from “className” to “class_name”

我的未来我决定 提交于 2019-12-04 22:22:12
问题 I'm using the JMSSerializerBundle to serialize my entity. but I have the following problem: the attribute name is "className" but in my Json object I get a "class_name". this is my entity: /** * Events * * @ORM\Table() * @ORM\Entity */ class Events { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; ... /** * @var string * * @ORM\Column(name="className", type="string", length=255) */ private $className; /** * Set

Serialize Doctrine array containing objects using inheritance

这一生的挚爱 提交于 2019-12-04 15:19:51
问题 Problem : When serializing a collection of Doctrine enitities the collection will still have 2 items though the items are empty. Background : I have a few entities which extends each other B extends A and C extends B . In the entity Test I have an array with objects of the type B . $test will have the expected values (collection with two items) at the moment of serialization. $test contains a variable (array) collection one of the items in the array is of the type B and one of type C . $sTest

How to achieve model side-loading with JMS Serializer and Symfony2

空扰寡人 提交于 2019-12-04 12:05:47
I'm building a project with Ember.js and Ember-data for the UI and Symfony2, FOSRestBundle and JMS Serializer for the backend JSON API. JMS Serializer always embeds nested models in its output, but Ember-data requires that the models are side-loaded . I can't find anywhere an example of configuring JMS Serializer to side-load models rather than embedding them. Of course, I could just write an adapter on the Ember-data side to transform the result , but I want to gain the benefits of side-loading data and not just work around a (potential) limitation in JMS Serializer. This is what I mean by

JMS Serializer ignores mappings for Knp Paginator

梦想的初衷 提交于 2019-12-04 11:24:13
问题 I have problem with exclusion of some KNP Paginator properties with JMS Serializer. First, this is included in composer.json ... "jms/serializer-bundle": "~0.13", "knplabs/knp-paginator-bundle": "2.4.*@dev", ... I'm paginating CrmContacts entity and exclusion policy for that entity works well. I also added yml file for KNP Paginator like this: config.yml jms_serializer: metadata: directories: KNPPB: namespace_prefix: 'Knp\\Bundle\\PaginatorBundle' path: %kernel.root_dir%/Resources/serializer

JMS Serializer Deserialize with abstract parent class

蹲街弑〆低调 提交于 2019-12-04 03:28:39
I have an abstract parent (mapped super-)class which has several children with different properties which I'd like to deserialize. I'm storing the data using MongoDB and Doctrine ODM, so I also have a discriminator field which tells doctrine which subclass is used (and also have a custom "type" property ontop which is used elsewhere to determine which class is currently processed). When deserializing my model, I get an exception telling me that its impossible to create an instance of an abstract class (ofcourse) - now I'm wondering how I can tell the JMS Deserializer which inherited class it

symfony2: JMSSerializerBundle changes the attribute name from “className” to “class_name”

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 13:56:47
I'm using the JMSSerializerBundle to serialize my entity. but I have the following problem: the attribute name is "className" but in my Json object I get a "class_name". this is my entity: /** * Events * * @ORM\Table() * @ORM\Entity */ class Events { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; ... /** * @var string * * @ORM\Column(name="className", type="string", length=255) */ private $className; /** * Set className * * @param string $className * @return Events */ public function setClassName($className) {

Serializing Entity Relation only to Id with JMS Serializer

╄→尐↘猪︶ㄣ 提交于 2019-12-03 06:42:17
问题 I'm trying to serialize a entity relation with JMS Serializer. Here is the Entity: class Ad { /** * @Type("string") * @Groups({"manage"}) * * @var string */ private $description; /** * @Type("Acme\SearchBundle\Entity\Country") * @Groups({"manage"}) * * @var \Acme\SearchBundle\Entity\Country */ private $country; /** * @Type("string") * @Groups({"manage"}) * * @var string */ private $title; /** * Set description * * @param string $description * @return Ad */ public function setDescription(

JMS Serializer ignores mappings for Knp Paginator

荒凉一梦 提交于 2019-12-03 06:11:38
I have problem with exclusion of some KNP Paginator properties with JMS Serializer. First, this is included in composer.json ... "jms/serializer-bundle": "~0.13", "knplabs/knp-paginator-bundle": "2.4.*@dev", ... I'm paginating CrmContacts entity and exclusion policy for that entity works well. I also added yml file for KNP Paginator like this: config.yml jms_serializer: metadata: directories: KNPPB: namespace_prefix: 'Knp\\Bundle\\PaginatorBundle' path: %kernel.root_dir%/Resources/serializer/Knp inside app/Resources/serializer/Knp folder I've created Pagination.SlidingPagination.yml: Knp

Doctrine2, PersistentCollection and JMS Serializer

一曲冷凌霜 提交于 2019-12-01 11:46:52
I have an Entity with a oneToMany relationship, I can get the associated items using; $this->getQueuedItems() This returns Doctrine\ORM\PersistentCollection object, I am then passing this to JMS Serializer like so; $serializer = $container->get('serializer'); $json = $serializer->serialize($this->getQueuedItems(), 'json'); But outputting $json using var_dump() results in; string(2) "[]" Which is wrong. There is data there, because if I do a foreach() over $this->getQueuedItems() I get data. How can I use JMS Serializer to serialise Doctrine\ORM\PersistentCollection into JSON? Thanks The

FOSRestBundle and JMSSerializer custom form error handler

旧时模样 提交于 2019-12-01 08:17:48
问题 I have written a custom Form Handler for JMSSerializerBundle that I'm using with FOSRestBundle. According to the documentation it should be as easy as tagging a service correctly. But my custom handler never gets used. Here's the handler: <?php namespace AppBundle\Handler; use JMS\Serializer\Handler\FormErrorHandler as JMSFormErrorHandler; class FormErrorHandler extends JMSFormErrorHandler { public function serializeFormToJson(\JMS\Serializer\JsonSerializationVisitor $visitor, \Symfony