jms-serializer

JMS Serializer serialize object in object with diffrent view

安稳与你 提交于 2019-12-06 17:26:10
I'm developing a RESTful service with Symfony2, JMS Serializer Bundle , FOS Rest Bundle and Hateoas Bundle . There are 2 entities User and Company and I want to, when I serialize a Company get larger detail. But, when serializing User related Company show only Company ID and name object or just ID as integer. I have serialize policy like below. User Acme\UserBundle\Entity\User: exclusion_policy: ALL xml_root_name: user properties: id: expose: true type: integer company: expose: true type: Acme\CompanyBundle\Entity\Company name: expose: true type: string surname: expose: true type: string

How to make JMS Serializer throw an exception on deserializing JSON instead of coercing types?

廉价感情. 提交于 2019-12-05 10:53:32
I'm trying to write a REST API which consumes a JSON from a PUT request in Symfony2. Deserializing the JSON to an entity sort of works – but the JMS Serializer seems to coerce types from the JSON instead of throwing an exception if the type of a property in the JSON does not match the entity’s corresponding property. For example … { "id" : "123" } … will result in … int(123) … if the property id is defined as an integer in the entity. But I would like JMS Serializer to throw an exception instead. Does anyone know how to achieve this? Update 2016-02-27 One problem with JMS Serializer’s type

Getting missmatch in datetime format using jms serializer and ISO8601

十年热恋 提交于 2019-12-05 07:21:24
I am getting this message: Invalid datetime "2017-11-07T19:46:57.118Z", expected format Y-m-d\\TH:i:sP. When using JMS Serializer and the config: jms_serializer: handlers: datetime: default_format: 'Y-m-d\\TH:i:sP' I think that my supplied date is in the correct format, but apparently not. Is it something that is wrong with the date? This is a tough one, I've run into it before. I was using annotations so my fix looked like: @Serializer\Type("DateTime<'Y-m-d\TH:i:s.uT'>") So I'm guessing yours is going to look like: jms_serializer: handlers: datetime: default_format: 'Y-m-d\TH:i:s.uT' Or you

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 VirtualProperty with argument and custom listener/subscriber

爱⌒轻易说出口 提交于 2019-12-02 12:13:20
问题 I am trying to serialize a property which is a Doctrine Criteria: public function getUserResults(User $user) { $criteria = Criteria::create() ->where(Criteria::expr()->eq('user', $user)) ; return $this->getResults()->matching($criteria); } I cannot use the @VirtualProperty because it needs an argument so I implemented a custom subscriber for one of my types following this post: https://stackoverflow.com/a/44244747 <?php namespace AppBundle\Serializer; use JMS\Serializer\EventDispatcher

JMS VirtualProperty with argument and custom listener/subscriber

懵懂的女人 提交于 2019-12-02 03:10:31
I am trying to serialize a property which is a Doctrine Criteria: public function getUserResults(User $user) { $criteria = Criteria::create() ->where(Criteria::expr()->eq('user', $user)) ; return $this->getResults()->matching($criteria); } I cannot use the @VirtualProperty because it needs an argument so I implemented a custom subscriber for one of my types following this post: https://stackoverflow.com/a/44244747 <?php namespace AppBundle\Serializer; use JMS\Serializer\EventDispatcher\EventSubscriberInterface; use JMS\Serializer\EventDispatcher\PreSerializeEvent; use Symfony\Component

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