Symfony serializer doesn't work with --no-dev

710 views Asked by At

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 = [];
2

There are 2 answers

0
Dinar On BEST ANSWER

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

property_info:
    enabled: true
1
E_p On

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