1

I'm using symfony serializer. But if I install composer packages with --no-dev flag, it deserializes data that supposed to be array of objects in array of arrays instead.

This is serialization:

$result = $this->get('serializer')->deserialize(
    $request->getContent(),
    InputDto::class,
    'json'
);

And for deserialization I use annotations in DTO.

This is how "field" looks in DTO for objects array:

/**
 * @var OrderItemDto[]|Collection
 */
private $items = [];
Dinar
  • 74
  • 1
  • 9

2 Answers2

2

Based on the code:

https://github.com/symfony/serializer/blob/master/Encoder/JsonDecode.php#L84

If you pass an option json_decode_associative as false

$result = $this->get('serializer')->deserialize(
    $request->getContent(),
    InputDto::class,
    'json',
    ['json_decode_associative' => false]
);

It should not try to convert it to array.

http://php.net/manual/en/function.json-decode.php

E_p
  • 3,136
  • 16
  • 28
  • Unfortunately this didn't help. It serialized JSON object to PHP stdClass but not the type we need. – Dinar Nov 16 '17 at 15:06
1

To make object sublevel work you need to add to app/config/config.yml in framework section next lines:

property_info:
    enabled: true
Dinar
  • 74
  • 1
  • 9