jmsserializerbundle

Custom Handler on JMSSerializerBundle is ignored

醉酒当歌 提交于 2020-02-01 02:54:11
问题 I am attempting to use a custom handler for JMS Serializer Bundle class CustomHandler implements SubscribingHandlerInterface { public static function getSubscribingMethods() { return array( array( 'direction' => GraphNavigator::DIRECTION_SERIALIZATION, 'format' => 'json', 'type' => 'integer', 'method' => 'serializeIntToJson', ), ); } public function serializeIntToJson(JsonSerializationVisitor $visitor, $int, array $type, Context $context) { die("GIVE ME SOMETHING"); } } This does nothing, and

JMS Serializer DateTime not deserializing?

做~自己de王妃 提交于 2020-01-06 20:09:31
问题 I have a sort of special setup of Symfony2, FOSRestBundle and JMSSerializerBundle, due to a legacy DB in the background. I'm struggling to get a PUT request working, including the deserialization of a DateTime property. First things first. This is a model snippet, notice the DateTime format: /** * @var \DateTime * * @ORM\Column(name="sys_lastmodifieddate", type="datetime", nullable=true) * * @Type("DateTime<'Y-m-d\TH:i:sP'>") * * @Expose */ private $sysLastmodifieddate; I have built a Form

how to update symfony2/doctrine entity from a @Groups inclusion policy JMSSerializer deserialized entity

跟風遠走 提交于 2019-12-28 12:31:29
问题 I'm trying to update symfony2/doctrine entities using JMSSerializer with an @ExclusionPolicy:None @Groups Inclusion Policy. * @Serializer\ExclusionPolicy("none") */ class Foo { /** * @Serializer\Groups({"flag","edit"}) */ protected $id; /** * @Serializer\Groups({"edit"}) */ protected $name; /** * @Serializer\Groups({"flag"}) */ protected $flag; /** * @Serializer\Exclude() */ protected $createdBy; } reference: http://jmsyst.com/libs/serializer/master/reference/annotations the result for the

Changing JMS serialization JSON label names, according to api level

自闭症网瘾萝莉.ら 提交于 2019-12-23 01:52:06
问题 I'm using jms/serializer-bundle with Symfony, and a serialization configuration in YML form, to serialize some Doctrine objects as JSON. An existing API means that some of the labels were named with underscores (e.g. "created_on") createdOn: expose: true groups: label serialized_name: created_on ... "created_on": "2014-03-06T14:28:17+0000", but I'd like to tidy this up for a new API version and return responses in camelCase for new API calls. I had hoped/thought that I could use the JMS

Add custom property to serialized object

依然范特西╮ 提交于 2019-12-22 16:40:44
问题 I'm developing RESTful API for a web service. And I need to expose some properties that do not belong to an entity itself. For example I have a Pizza entity object, it has it's own size and name properties. I'm outputting it in JSON format with FOSRestBundle and JMSSerializer . I've setup properties annotations for this entity to expose needed properties via serialization groups and it's working great. But I need to add some properties that do not belong to the entity itself. For example I

Format input and output fields with JMSSerializer (handle single property)

拜拜、爱过 提交于 2019-12-22 07:38:18
问题 I would like to handle a single object property on serialization and deserialization with JMSSerializer. Suposing we have this class : class Task { const STATUS_PENDING = 0; const STATUS_OVER = 1; protected $status; /* getter and setter */ public function getStatusLabel() { return ['pending', 'over'][$this->getStatus()]; } public static function getStatusFromLabel($label) { return [ 'pending' => self::STATUS_PENDING, 'over' => self::STATUS_OVER ][$label]; } } I would like to return instances

Symfony Restful Post: JMSSerializerBundle vs Symfony Form Components

核能气质少年 提交于 2019-12-22 06:24:34
问题 As far as i understand it right JMSSerializerBundle's deserialisation does the same same as the symfony form component when a controller gets an post/put/patch request? So either i create a symfony custom formType for e.g. an UserType and when i get a request i do something like $form->handleRequest($request) or i use JMSSerializerBundle to unserialize the request to a document/entity which gets finally stored. Does anyone have experience with both methods? Currently i'm only familiar with

Symfony Restful Post: JMSSerializerBundle vs Symfony Form Components

我与影子孤独终老i 提交于 2019-12-22 06:24:33
问题 As far as i understand it right JMSSerializerBundle's deserialisation does the same same as the symfony form component when a controller gets an post/put/patch request? So either i create a symfony custom formType for e.g. an UserType and when i get a request i do something like $form->handleRequest($request) or i use JMSSerializerBundle to unserialize the request to a document/entity which gets finally stored. Does anyone have experience with both methods? Currently i'm only familiar with

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

佐手、 提交于 2019-12-21 20:54:07
问题 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

JMS Serializer Deserialize with abstract parent class

蓝咒 提交于 2019-12-21 09:31:27
问题 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