
Description
This issue is automatically created based on existing pull request: #28140: Fixed the problem with products create/update via REST API requests when request body data is sent as "xml"
Fixed the problem with products create/update via REST API requests when request body data is sent as "xml"
Description (*)
After updating Magento to v. 2.3.5 there is no more possibility to send REST API requests for creating/updating products with "xml" request body. Every request leads to a response with an error: "Decoding error: Unable to unserialize value. Error:..."
The problem appeared after adding the class "Magento\Catalog\Model\Product\Webapi\ProductOutputProcessor" which additionally processes product data during preparing API response.
This class uses deserializer class ("Magento\Framework\Webapi\Rest\Request\DeserializerInterface" inherited class instance) for the processing (converting) request body (interface injected in the constructor).
Different deserializer class configured (via di.xml) for REST and SOAP scopes: "Magento\Framework\Webapi\Rest\Request\Deserializer\Json" (for REST) and Magento\Framework\Webapi\Rest\Request\Deserializer\XML (for SOAP).
f58ddb5#diff-8f3c9c53a4d283c4a677a3bfd544a363R40
Such configuration leads to parsing errors in product REST API requests when product request data sent as XML because ProductOutputProcessor will always use Json deserializer for converting request body data without checking origin request content-type (which could be XML).
For fixing this I have implemented custom deserializer class for products rest requests:
Magento\Catalog\Model\Product\Webapi\Rest\RequestTypeBasedDeserializer
This class first checks content-type for request body and then, using deserializer factory, get needed deserializer instance and use it for converting request body data.
-->
Manual testing scenarios (*)
Test on Magento version 2.3.5 or using 2.4-develop branch
- Sent product create/update request with XML request body and "Content-Type: application/xml" header.
Example:
curl --location --request POST 'https://magento-site/rest/all/V1/products' \
--header 'Authorization: Bearer someencodedtoken' \
--header 'Content-Type: application/xml' \
--data-raw '<?xml version='\''1.0'\'' encoding='\''UTF-8'\''?>
<products>
<product>
<sku>TRAKTOR_KONTROL_BAG_1</sku>
<name>TRAKTOR_KONTROL_BAG_1</name>
<weight>22</weight>
<attribute_set_id>4</attribute_set_id>
<status>2</status>
</product>
</products>
- Got an error in response with the text: "Decoding error: Unable to unserialize value. Error:..."
Contribution checklist (*)
- Pull request has a meaningful description of its purpose
- All commits are accompanied by meaningful commit messages
- All new or changed code is covered with unit/integration tests (if applicable)
- All automated tests passed successfully (all builds are green)