I have a simple entity
/**
* @var string|null
*
* @ORM\Column(name="city", type="string", length=255, nullable=false)
* @Assert\NotNull()
*/
private $city;
...
/**
* @param string|null $city
* @return CustomerAddressList
*/
public function setCity(?string $city): CustomerAddressList
{
$this->city = $city;
return $this;
}
If I try to pass null to the field city the result is a runtime exception instead of a validation error:
{
"@context": "/api/v2/contexts/Error",
"@type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "The type of the address attribute must be string, NULL given."
}
If I change nullable=false to true then everything works fine, but it's not an acceptable solution.
How can I fix it?
nullas a value I would like to have a validation error.