Open soullivaneuh opened 5 years ago
More info. Here is the post action:
/**
* @QueryParam(name="record", key=null)
*
* @ParamConverter("record", converter="fos_rest.request_body")
*
* @IsGranted("edit", subject="domain")
*/
public function postAction(PowerDNSDomain $domain, PowerDNSRecord $record, ConstraintViolationListInterface $validationErrors): View
{
if ($validationErrors->count() > 0) {
return $this->handleBodyValidationErrorsView($validationErrors);
}
$record
->setDomain($domain)
->setName($record->getName())
->setType($record->getType())
;
$this->get('manager.dns')->saveRecord($record);
$view = $this->view($record, 201);
$view->getContext()->setGroups(['details']);
return $view;
}
Also, if I try to dirty change the code on SymfonySerializerAdapter
:
/**
* {@inheritdoc}
*/
public function deserialize($data, $type, $format, Context $context)
{
$newContext = $this->convertContext($context);
if ($type === PowerDNSRecord::class) {
$newContext['default_constructor_arguments'] = [
PowerDNSRecord::class => ['domain' => new PowerDNSDomain()],
];
}
return $this->serializer->deserialize($data, $type, $format, $newContext);
}
It works.
I think the issue is your input data, constructor arguments are entirely managed by symfony serializer.
Did you actually put something under domain
in your input?
@GuilhemN not on the body, and AFAIK I shouldn't because the URL is POST /dns/{domain_id}/records
.
The domain_id
is used to retrieve the domain.
This is not a supported case, the serializer doesn't know about other request parameters, the only solution I see is to deserialize your input by hand (with https://symfony.com/doc/current/components/serializer.html#handling-constructor-arguments).
i have a question about your move from JMS to Symfony serializer, any raison ? or just for testing ? I have the same issue in JMS before i found a bit code that help me to fix that.
I just move from JMS to Symfony serializer without touching the API itself. I have this entity:
And this error on creation POST request:
I found this serializer documentation note about this: https://symfony.com/doc/current/components/serializer.html#handling-constructor-arguments
But I don't know about FOSRest. Is it correctly handled?