JMS序列化器在Mysql BLOB反序列化时返回资源id #xxx


JMS Serializer return Resource id #xxx on Mysql BLOB deserialize

我正在Symfony 3项目中使用JMS序列化器。当我读取具有blob值的实体时,json返回:Resource id #xxx

默认不支持blob类型吗?我该怎么做呢?

我通过让getter总是为您打开资源并强制JMS Serialiser使用该getter而不是默认的反射来解决这个问题。

/**
 * @ORM'Column(type="blob")
 * @Serializer'Type("string")
 * @Serializer'AccessType("public_method")
 */
private $payload;
public function getPayload(): string
{
    if ('is_resource($this->payload)) {
        return stream_get_contents($this->payload);
    }
    return $this->payload;
}
public function setPayload(string $payload): void
{
    $this->payload = $payload;
}

使用:<?= get_resource_type($data_example) ?>如果返回类型=流你可以使用<?php stream_get_contents($data_example); ?>

祝你好运!