I have the following entity (only attached the relevant parts):
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(mercure=true)
* @ORM\Entity(repositoryClass="App\Repository\EventRepository")
*/
class Event {
/**
* @ORM\Column(type="datetime")
* @Assert\DateTime
* @Assert\NotNull
*/
private $createdAt;
public function __construct() {
$this->createdAt = new \DateTime();
}
public function getCreatedAt(): ?\DateTimeInterface {
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self {
$this->createdAt = $createdAt;
return $this;
}
}
Its repository:
class EventRepository extends ServiceEntityRepository {
public function __construct(ManagerRegistry $registry) {
parent::__construct($registry, Event::class);
}
}
When creating a POST request to the event endpoint (via Postman or the Swagger UI), it fails with the following exception:
{ "name": "test", "@creator": "/people/23", "description": "desc" }
though that's quite irrelevant, as the error is at thecreatedAt
property which is initialized in the constructor – HeerlenEvent
yourself and validate it manually, if you would have the issue (it would at least remove complexity). Maybe it's the way ApiPlatform loads the object? – Woodburydump()
what it's getting to check, this is where I would start. – Woodbury