我有被暴露的API平台的资源实体,并包含以下属性:API平台 - 更新可为空字符串错误
/**
* @ORM\Column(type="string", nullable=true)
*/
private $note;
当我尝试更新的实体(通过PUT)发送以下JSON:
{
"note": null
}
我从Symfony的串行以下错误:
[2017年6月29日21时47分33秒]请求.CRITICAL:未捕获到的PHP异常Symfony \ Component \ Serializer \ Exception \ UnexpectedValueException:“在/ var/www/html/testapp/server/vendor/symfony/symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php第196行{“exception”:“[object](Symfony \ Component \ Serializer \ Exception \ UnexpectedValueException(code:0):\”string \“,\” NULL“,在/var/www/html/testapp/server/vendor/symfony/symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php:196,Symfony \ Component \ PropertyAccess \ Exception \ InvalidArgumentException(代码: 0):在/var/www/html/testapp/server/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php:275处给出的类型\“string \”,\“NULL \”的预期参数)“} []
这似乎是我错过了一些配置,以允许此属性上的空值?为了让事情变得怪异,当我得到一个包含空音符的资源,那么说明是正常返回NULL:
{
"@context": "/contexts/RentPayment",
"@id": "/rent_payments/1",
"@type": "RentPayment",
"id": 1,
"note": null,
"date": "2016-03-01T00:00:00+00:00"
}
我缺少什么 - PS我是一个巨大的福利局到API平台
只是一个狂野的刺,但你使用类型暗示二传手? –
谢谢!呃,为什么我没有想到 - 如果你愿意,可以把它作为答案加进去。 – dblack