Skip to content
Advertisement

Why do I receive “This value should be of type string” when using a DateTime constraint on Symfony 5?

I have the following entity (only attached the relevant parts):

JavaScript

Its repository:

JavaScript

When creating a POST request to the event endpoint (via Postman or the Swagger UI), it fails with the following exception:

profiler

Advertisement

Answer

You are using the wrong of assertion.

Date expects a string or an object that can be cast into a string. And a DateTimeInterface is neither.

You should be using a Type constraint.

JavaScript

The ability to use AssertDate to validate DateTime objects was deprecated on Symfony 4.2, and on Symfony 5.0 it was removed altogether.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement