Description
Summary
Using a class for the message queue request type, and having the properties in the constructor using camel-case names, the object cannot be instantiated properly as the object data keys are converted to snake-case.
Tested/reporting on 2.4.6-p6, though i don't think it has changed in a while.
Examples
<?php
namespace \Test\Module\Model;
class SyncRequestData
{
/**
* @var int
*/
private $storeId;
/**
* @var int[]
*/
private $sessionIds;
/**
* @var int
*/
private $websiteStoreId;
/**
* @param int $storeId
* @param int[] $sessionIds
* @param int $websiteStoreId
*/
public function __construct(
int $storeId,
array $sessionIds,
int $websiteStoreId
) {
$this->storeId = $storeId;
$this->sessionIds = $sessionIds;
$this->websiteStoreId = $websiteStoreId;
}
/**
* @return int
*/
public function getStoreId(): int
{
return $this->storeId;
}
/**
* @return int[]
*/
public function getSessionIds(): array
{
return $this->sessionIds;
}
/**
* @return int
*/
public function getWebsiteStoreId(): int
{
return $this->websiteStoreId;
}
}
(Magento\Framework\MessageQueue\MessageEncoder calls the service input and output processors)
Magento\Framework\Webapi\ServiceOutputProcessor::convertValue
converts the class to the following:
{"store_id":3,"session_ids":[1],"website_store_id":1}
Then in \Magento\Framework\Webapi\ServiceInputProcessor::getConstructorData
, the keys do not match since they were converted to snake-case, but they are expected in camel-case, so an empty array is passed to objectmanager to create the object, resulting in an error due to not passing any arguments to constructor.
The only way I can currently get around this issue is having the class extend AbstractSimpleObject or DataObject and adding setters (or using the data constructor argument)
Proposed solution
No response
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.