diff --git a/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php b/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php index 43b8cc22ebf2c..01661cf24ba04 100644 --- a/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php @@ -46,6 +46,11 @@ class DataObjectProcessor */ private $processors; + /** + * @var array + */ + private $objectKeyMap; + /** * @param MethodsMap $methodsMapProcessor * @param TypeCaster $typeCaster @@ -53,6 +58,7 @@ class DataObjectProcessor * @param CustomAttributesProcessor $customAttributesProcessor * @param ExtensionAttributesProcessor $extensionAttributesProcessor * @param array $processors + * @param array $objectKeyMap */ public function __construct( MethodsMap $methodsMapProcessor, @@ -60,7 +66,8 @@ public function __construct( FieldNamer $fieldNamer, CustomAttributesProcessor $customAttributesProcessor, ExtensionAttributesProcessor $extensionAttributesProcessor, - array $processors = [] + array $processors = [], + array $objectKeyMap = [] ) { $this->methodsMapProcessor = $methodsMapProcessor; $this->typeCaster = $typeCaster; @@ -68,6 +75,7 @@ public function __construct( $this->extensionAttributesProcessor = $extensionAttributesProcessor; $this->customAttributesProcessor = $customAttributesProcessor; $this->processors = $processors; + $this->objectKeyMap = $objectKeyMap; } /** @@ -128,7 +136,7 @@ public function buildOutputDataArray($dataObject, $dataObjectType) } } - $outputData[$key] = $value; + $outputData[$this->getKeyByObjectType($key, $dataObjectType)] = $value; } $outputData = $this->changeOutputArray($dataObject, $outputData); @@ -153,4 +161,21 @@ private function changeOutputArray($dataObject, array $outputData): array return $outputData; } + + /** + * @param string $key + * @param string $dataObjectType + * @return string + */ + private function getKeyByObjectType(string $key, string $dataObjectType): string + { + $dataObjectType = ltrim($dataObjectType, '\\'); + if ( + array_key_exists($dataObjectType, $this->objectKeyMap) && + array_key_exists($key, $this->objectKeyMap[$dataObjectType]) + ) { + $key = $this->objectKeyMap[$dataObjectType][$key]; + } + return $key; + } }