-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Closed
Labels
Component: ApiUse with concrete module component label E.g. "Component: Api" + "Catalog"Use with concrete module component label E.g. "Component: Api" + "Catalog"Event: cd-cologne19Fixed in 2.4.xThe issue has been fixed in 2.4-develop branchThe issue has been fixed in 2.4-develop branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseThe issue has been reproduced on latest 2.3 release
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
Component: ApiUse with concrete module component label E.g. "Component: Api" + "Catalog"Use with concrete module component label E.g. "Component: Api" + "Catalog"Event: cd-cologne19Fixed in 2.4.xThe issue has been fixed in 2.4-develop branchThe issue has been fixed in 2.4-develop branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseThe issue has been reproduced on latest 2.3 release