[英]Symfony serializer doesn't work with --no-dev
I'm using symfony serializer. 我正在使用symfony序列化程序。 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. 但是,如果我使用
--no-dev
标志安装composer包,它会反序列化数组,这些数据应该是数组数组中的对象数组。
This is serialization: 这是序列化:
$result = $this->get('serializer')->deserialize(
$request->getContent(),
InputDto::class,
'json'
);
And for deserialization I use annotations in DTO. 对于反序列化,我在DTO中使用注释。
This is how "field" looks in DTO for objects array: 这就是DTO中对象数组的“字段”外观:
/**
* @var OrderItemDto[]|Collection
*/
private $items = [];
Based on the code: 基于代码:
https://github.com/symfony/serializer/blob/master/Encoder/JsonDecode.php#L84 https://github.com/symfony/serializer/blob/master/Encoder/JsonDecode.php#L84
If you pass an option json_decode_associative as false 如果将选项json_decode_associative传递为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 http://php.net/manual/en/function.json-decode.php
To make object sublevel work you need to add to app/config/config.yml
in framework
section next lines: 要使对象分段工作,您需要在
framework
部分的下一行添加到app/config/config.yml
:
property_info:
enabled: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.