Questions tagged [jms-serializer]

Serializer is a library, that allows you to (de-)serialize data of any complexity. It supports XML, JSON, and YAML.

Serializer is a library, that allows you to (de-)serialize data of any complexity. Currently, it supports XML, JSON, and YAML.

Website: http://jmsyst.com/libs/serializer

It also provides you with a rich tool-set to adapt the output to your specific needs.

Built-in features include:

  • (De-)serialize data of any complexity; circular references are handled gracefully.
  • Supports many built-in PHP types (such as dates)
  • Integrates with Doctrine ORM, et. al.
  • Supports versioning, e.g. for APIs
  • Configurable via PHP, XML, YAML, or Doctrine Annotations
222 questions
11
votes
2 answers

Deserialize array of object using jms/serializer

I want to deserialize something like this: [ { "id": 42 }, { "id": 43 } ] Any idea how to do this?
mykiwi
  • 1,671
  • 1
  • 19
  • 35
9
votes
2 answers

Unable to serialize empty array to empty XML element with JMS serializer

I am assembling an XML file based on an XSD that requires an XML container element to be present, even if it is empty. When I try to serialize an empty array, using JMS serializer, with configuration that works if the array is not empty, I get no…
rhummelmose
  • 647
  • 4
  • 15
8
votes
2 answers

Getting missmatch in datetime format using jms serializer and ISO8601

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…
rablentain
  • 6,641
  • 13
  • 50
  • 91
8
votes
2 answers

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?

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…
Jason McClellan
  • 2,931
  • 3
  • 23
  • 32
7
votes
2 answers

Is it possible to serialize an array to the root of an object with JMS Serializer?

Imagine I have a simple object, structured similarly to the one below: Object (SomeClass) { $someOtherData (array) [ ... ] $data (array) [ "key": "value", "key": "value", "key": "value", "key":…
Seer
  • 5,226
  • 5
  • 33
  • 55
6
votes
1 answer

How to use inherited classes with API-Platform

I wish to use API-Platform to perform CRUD operations on object hierarchy classes. I found little written when using inherited classes with API-Platform and some but not much more when used with Symfony's serializer, and am looking for better…
user1032531
  • 24,767
  • 68
  • 217
  • 387
6
votes
2 answers

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

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…
6
votes
2 answers

Serializing traits with JMSSerializer

When trying to serialize a model that uses traits, JMSSerializer does not serialize properties included by that trait. I am using yaml to configure the serializer but it seems that it's not working. trait IdentityTrait { protected $id; …
user2359967
5
votes
2 answers

JMS Serializer not serializing child classes

I have problem with JMS serializer. When I use groups, JMS not serializes my child classes, but when i dont use groups all is okay. What i doing wrongly? $context = SerializationContext::create()->enableMaxDepthChecks(); …
5
votes
3 answers

Symfony2 Doctrine2 De-Serialize and Merge Entity issue

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 | …
Shawn Northrop
  • 5,826
  • 6
  • 42
  • 80
5
votes
0 answers

JMS Serializer XmlList annotation

How to define cdata and namespace for @XmlList elements? For example if I need to modify BlogPost from the example http://jmsyst.com/libs/serializer/master/reference/annotations#xmlnamespace to have multiple authors: use JMS\Serializer\Annotation…
Alex Blex
  • 34,704
  • 7
  • 48
  • 75
4
votes
0 answers

Symfony serializer Virtual Property like JMS Expression Prop

I'm on a project currently using JMS Serializer in an API. We use a lot of virtual properties - especially expression Prop in the serialization mapping. App\Entity\MyEntity: exclusion_policy: none properties: id: expose: true …
4
votes
2 answers

@JMS\Exclude only if a property is empty

I am using JMS\Serializer in my project and I want to ignore one property only if the array in it is empty. I tried something like : @JMS\Exclude(if="count('$this->required') === 0") or @JMS\Exclude(if="empty('required')") but got a syntax…
4
votes
0 answers

JMS Serializer nested objects policy

I have a similar question as JMS Serializer serialize object in object with diffrent view, but I can't get it work like in the accepted answer. I have a User model that has many Reviews, but the Reviews owner is another User. I have a serialization…
4
votes
0 answers

Deserialize AWS Result / Nested JSON with JMS Serializer

I'm trying to deserialize data from AWS CloudSearch with JMS Serializer. The JSON-encoded data from AWS Result looks something like this: { id: 1234, fields: { "field1": ["value1"], "field2": ["value2"] } } The entity serializer…
tmirks
  • 503
  • 5
  • 11
1
2 3
14 15