我正在序列化的一个类有一个我想看到的虚拟属性。我正在使用 yaml 配置。
这是yaml:
Namespace\Model\Keg:
exclusion_policy: ALL
properties:
A list of properties that work
virtual_properties:
getKegImage:
serialized_name: image
这是课程:
namespace Namespace\Model;
class Keg extends ModelAbstract
{
/** Some properties + accessors **/
/**
* @param bool $asImgTag Whether or not to return the URL in an <img> tag
* @return array
*/
public function getKegImage ($asImgTag = false)
{
return [
'Key' => 'value',
'Key' => 'value',
'Key' => 'value'
];
}
}
当我序列化模型时,我希望在 json 中看到一个图像字段,其中数组作为它的值。相反,该字段丢失。我在 yaml 文件中尝试了许多设置组合,但无法显示。