jmsserializerbundle

Doctrine2, PersistentCollection and JMS Serializer

我的梦境 提交于 2019-12-01 08:15:40
问题 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.

JMS Serializer: how to use camel case for properties

只愿长相守 提交于 2019-12-01 04:04:22
I'm using FOS Rest bundle and JMS Serializer to create a REST Api. The problem is I would like to keep the property names in the JSON response camel cased instead of using _. For example, I have a property called employeeIdentifier, by default that gets converted to employee_identifier. I saw that there's an option in the config to disable the lowercase and get rid of the _, but then it becomes EmployeeIdentifier. Is there any way that JMS Serializer keeps the original name of the property? Thanks in advance I found a way to do it globally, if you want to keep the property names as is you need

JMS Serializer: how to use camel case for properties

走远了吗. 提交于 2019-12-01 01:12:33
问题 I'm using FOS Rest bundle and JMS Serializer to create a REST Api. The problem is I would like to keep the property names in the JSON response camel cased instead of using _. For example, I have a property called employeeIdentifier, by default that gets converted to employee_identifier. I saw that there's an option in the config to disable the lowercase and get rid of the _, but then it becomes EmployeeIdentifier. Is there any way that JMS Serializer keeps the original name of the property?

JMS Serializer: How to limit the depth of serialisation for an object graph

江枫思渺然 提交于 2019-11-30 23:39:53
Maybe it is just my misunderstanding of this annotation however it does not seam to work as expected. I have the following object graph User -> Company -> Users -> Groups -> Permissions As you can see there will be some recursion. JMS handles this quite well by not serialising the other user's company properties as well as not the current user. However I want the serialization to stop at and include company. I have tried this expecting that once the level $context->level = 2 it would stop <?php namespace FinalConcept\TimeTracker\EntitiesBundle\Entity; use Doctrine\Common\Collections

Add extra fields using JMS Serializer bundle

我与影子孤独终老i 提交于 2019-11-30 06:19:11
问题 I've an entity I usually serialize using the JMS Serializer bundle. I have to add to the serialization some fields that doesn't reside in the entity itself but are gathered with some db queries. My idea was to create a custom object, fill the fields with the entity fields and add the custom one. But this seems a bit tricky and expensive to do for every variation (I use lot of serialization groups) of the class. Is there a better/standard way to do this? Using a factory? Pre/Post serialization

Symfony - Deserialize json to an array of entities

有些话、适合烂在心里 提交于 2019-11-30 01:57:36
I have a json object that I received by making a get API call. I make this call to receive a list of objects. It's a list of post... So I have an array of Post Objects. Here the output : { "total":2, "data":[ { "id":2, "user":{ "id":1, "username":"sandro.tchikovani" }, "description":"cool", "nb_comments":0, "nb_likes":0, "date_creation":"2014-04-13T20:07:34-0700" }, { "id":1, "user":{ "id":1, "username":"sandro.tchikovani", }, "description":"Premier pooooste #lol", "nb_comments":0, "nb_likes":0, "date_creation":"2014-04-13T15:15:35-0700" } ] } I would like to deserialize the data part... The

How do I create a custom exclusion strategy for JMS Serializer that allows me to make run-time decisions about whether to include a particular field?

心不动则不痛 提交于 2019-11-29 14:35:29
问题 As the title says, I am trying to make a run-time decision on whether or not to include fields in the serialization. In my case, this decision will be based on permissions. I am using Symfony 2, so what I'm looking to do is add an additional annotation called @ExcludeIf which accepts a security expression. I can handle the annotation parsing and storing of the meta data, but I am not able to see how to integrate a custom exclusion strategy with the library. Any suggestions? Note: exclusion

JMSSerializer deserialize entity by id

☆樱花仙子☆ 提交于 2019-11-29 10:39:16
i'm using JMSSerializer to deserialize a JSON request and i'm having troubles with ManyToOne relations. I would like to deserialize the relation entity from a id given. Example: Class Game { /** * @var Team * * @ORM\ManyToOne(targetEntity="Team") * @ORM\JoinColumn(name="home_team_id", referencedColumnName="id") * @JMSSerializer\SerializedName("home") */ private $homeTeam; /** * @ORM\ManyToOne(targetEntity="Team") * @ORM\JoinColumn(name="visitor_team_id", referencedColumnName="id") * @JMSSerializer\SerializedName("visitor") */ private $visitorTeam; } So when i get this Json {"home": "id1",

Symfony2, FOSRestBundle. How to use group with JMSSerializerBundle?

╄→гoц情女王★ 提交于 2019-11-29 04:09:18
I have entity: <?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation\Groups; //... /** * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") **/ class User extends BaseUser { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") * @Groups({"default"}) */ protected $id; /** * @ORM\ManyToMany(targetEntity="StorageBundle\Entity\File") * @ORM\JoinTable(name="users_photos", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="photo_id",

Symfony - Deserialize json to an array of entities

心已入冬 提交于 2019-11-28 22:54:16
问题 I have a json object that I received by making a get API call. I make this call to receive a list of objects. It's a list of post... So I have an array of Post Objects. Here the output : { "total":2, "data":[ { "id":2, "user":{ "id":1, "username":"sandro.tchikovani" }, "description":"cool", "nb_comments":0, "nb_likes":0, "date_creation":"2014-04-13T20:07:34-0700" }, { "id":1, "user":{ "id":1, "username":"sandro.tchikovani", }, "description":"Premier pooooste #lol", "nb_comments":0, "nb_likes"