我目前有这个实体,我想在我的JSON中显示我的属性“ firedDate”,即使该值为null。
/**
* @ApiResource(normalizationContext={"groups"={"employee"}})
* @ApiFilter(DateFilter::class, properties={"dateProperty": DateFilter::INCLUDE_NULL_BEFORE_AND_AFTER})
* @ORM\Table(name="employee")
*/
class Employee
{
// ...
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"employee"})
*/
private $firedDate;
public function getFiredDate(): ?\DateTimeInterface
{
return $this->firedDate;
}
// ...
}
我做错了什么?:/ 谢谢!
我认为我找到了解决此问题的正确方法。设置skip_null_values
在false
您的normalizationContext
:
* @ApiResource(
* itemOperations={
* "get" = {
* //...
* }
* "put" = {
* //...
* },
* "patch" = {
* //...
* }
* },
* collectionOperations={
* "get",
* "post" = {
* //...
* }
* },
* normalizationContext={
* "skip_null_values" = false,
* "groups" = {"object:read"}
* },
* denormalizationContext={"groups" = {"object:write"}}
* )
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句