jms-serializer

Deserialize XML to Entity with nested nodes using JMS Serializer

穿精又带淫゛_ 提交于 2019-12-24 00:48:07
问题 I want to deserialize an XML file into an Entity using JMS Serializer. It works pretty well for direct properties. But when it comes to nested properties, I can't make it work without creating related entities. For example : <idt> <rcs>XXXXXXX</rcs> <name>NAME</name> <main> <adr_1> <type>YYYYY</type> <street>YYYYYYY</street> <zip>XXXXX</zip> </adr_1> </main> </idt> I need to create an Idt entity, and the deserialization will work fine for rcs and name , but for main I have to create a Main

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

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

Unable to override JMS Serializer's default handler for Symfony ConstraintViolationList

我怕爱的太早我们不能终老 提交于 2019-12-11 04:36:50
问题 I am unable to override default handlers in jms serializer bundle. I'd like to change the way Symfony\Component\Validator\ConstraintViolationList is serialized so I wrote my own custom handler. And tagged it correctly as described in the documentation (and in various stackoverflow answers). However, my handler keeps being overridden by the default handler for ConstraintViolationList that JMS Serializer bundle ships with. I've tagged my handler service correctly. In fact, my handler service is

Symfony2 Doctrine2 De-Serialize and Merge Entity issue

南笙酒味 提交于 2019-12-10 15:07:41
问题 I am trying to de-serialize json into an Entity and then Merge the Entity. I believe I had this working in the past where I would send the ID and any fields I wished to update. For example: In my DB: | id | first | last | city | | 1 | Jimmy | James | Seattle | I would then de-serialize the following json and merge the entity $json = { "id" : 1, "city": "chicago"} $customer = $serializer->deserialize($json, 'App\CustomerBundle\Entity\Customer', 'json'); $em->merge($customer); the expected

JMS Serializer serialize object in object with diffrent view

心不动则不痛 提交于 2019-12-08 08:19:42
问题 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

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

╄→гoц情女王★ 提交于 2019-12-07 04:24:56
问题 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

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

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