Closed
Description
Preconditions
- Magento 2.3.2 & 2.3-develop
Steps to reproduce
Create an interface with a nullable getter. In our scenario it was a method that could return an array of instances of another object, or null
:
/**
* @return null|\Vendor\Module\Api\Data\CompanyAddressInterface[]
*/
public function getAddresses(): ?array;
Expected result
When properly configured and used as a web API, the object should be serialized using Reflection and it's nested objects as well.
Actual result
The following error is thrown:
Possible cause
My guess is that when determinating the type of return class, something goes wrong when a return type can be nullable. See also the workaround:
Workaround
The current woraround that will not trigger this error and make the web API work as expected is to flip the arguments, so instead of:
/**
* @return null|\Vendor\Module\Api\Data\CompanyAddressInterface[]
*/
public function getAddresses(): ?array;
I use:
/**
* @return \Vendor\Module\Api\Data\CompanyAddressInterface[]|null
*/
public function getAddresses(): ?array;
Now everything works as expected, but it seems to me that this should be considered a bug.
Metadata
Metadata
Assignees
Labels
Use with concrete module component label E.g. "Component: Api" + "Catalog"The issue has been fixed in 2.4-develop branchGate 2 Passed. Manual verification of the issue description passedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentThe issue has been reproduced on latest 2.3 release