我试图通过API保存中给出的对象
所以我在失眠症中做了这个物体测试:
{
"rate": 1.59,
"correction":"2 ui nOVORAPID",
"date": "2020-11-26",
"time": "7:30"}我不明白为什么我有这个错误
未能对“App\Entity\Blood砂糖”类的属性"date“值进行去denormalize :类型为"string”、"object“在属性路径"date”的预期参数。
我的控制器:
$user = $this->getUser();
$jsonReceived = $request->getContent();
$json = json_decode($jsonReceived);
$newBloodsugar = $serializer->deserialize($jsonReceived, BloodSugar::class, 'json');
...我想Symfony不承认日期格式"Y-m-d",我怎么能这样做呢?
发布于 2020-12-02 06:01:45
我猜您的BloodSugar类具有无效的setter或属性类型。通常情况下,symfony-serializer将日期规范化为日期时间,而实体则期待字符串。尝试将其更改为DatetimeInterface,如下所示:
class BloodSugar {
//..
private ?DatetimeInterface $date;
//..
public function setDate(DatetimeInterface $date){
$this->date = $date;
return $this;
}
//..
}https://stackoverflow.com/questions/65096906
复制相似问题