jmsserializerbundle

Getting missmatch in datetime format using jms serializer and ISO8601

↘锁芯ラ 提交于 2019-12-07 03:41:40
问题 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? 回答1: 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

JMSSerializerBundle complex generated value

假装没事ソ 提交于 2019-12-07 02:35:48
问题 I need implement RESTful API for my site on symfony 2, so i use FOSRestBundle + JMSSerializerBundle I have such serializer yml for my entity: Acme\DemoBundle\Entity\Product: exclusion_policy: ALL accessor_order: custom custom_accessor_order: [id, title] properties: id: expose: true title: expose: true virtual_properties: getMainPhoto: serialized_name: photo The problem is that getMainPhoto return me url to full sized image. I want preprocess this url before sending response to api client

Changing JMS serialization JSON label names, according to api level

a 夏天 提交于 2019-12-06 22:13:29
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 Serializer "Until" and "Since" configurations to reference my Entity's properties twice, one with the old

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

Deserializing XML array

眉间皱痕 提交于 2019-12-06 13:18:30
I'm using an API that returns XML. I can retrieve one or multiple accounts with the API. I am using the Jms Serializer to deserialize this data into simple model classes that will hold the data. An account looks like <account href="https://your-subdomain.recurly.com/v2/accounts/1"> ... <account_code>1</account_code> <state>active</state> <username nil="nil"></username> <email>verena@example.com</email> <first_name>Verena</first_name> <last_name>Example</last_name> ... <address>...</address> </account> I've managed to configure my Account object as follows, which works fine when deserializing:

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

此生再无相见时 提交于 2019-12-05 12:16:09
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 of Task threw a REST API (using FOSRestBundle). The problem is that I don't want to return the raw

Symfony Restful Post: JMSSerializerBundle vs Symfony Form Components

我是研究僧i 提交于 2019-12-05 11:45:17
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 the form way... Which one should i choose? The Application i'm talking about is purely Restful, there are

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

JMSSerializerBundle complex generated value

对着背影说爱祢 提交于 2019-12-05 07:55:12
I need implement RESTful API for my site on symfony 2, so i use FOSRestBundle + JMSSerializerBundle I have such serializer yml for my entity: Acme\DemoBundle\Entity\Product: exclusion_policy: ALL accessor_order: custom custom_accessor_order: [id, title] properties: id: expose: true title: expose: true virtual_properties: getMainPhoto: serialized_name: photo The problem is that getMainPhoto return me url to full sized image. I want preprocess this url before sending response to api client where i can generate new url to resized version of such image. I already have service in sf2 which can do

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