diff --git a/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php b/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php index 2f3caf08c534e..ee73037512a0f 100644 --- a/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php @@ -45,6 +45,11 @@ class DataObjectProcessor */ private $processors; + /** + * @var array + */ + private $objectKeyMap; + /** * @param MethodsMap $methodsMapProcessor * @param TypeCaster $typeCaster @@ -52,6 +57,7 @@ class DataObjectProcessor * @param CustomAttributesProcessor $customAttributesProcessor * @param ExtensionAttributesProcessor $extensionAttributesProcessor * @param array $processors + * @param array $objectKeyMap */ public function __construct( MethodsMap $methodsMapProcessor, @@ -59,7 +65,8 @@ public function __construct( FieldNamer $fieldNamer, CustomAttributesProcessor $customAttributesProcessor, ExtensionAttributesProcessor $extensionAttributesProcessor, - array $processors = [] + array $processors = [], + array $objectKeyMap = [] ) { $this->methodsMapProcessor = $methodsMapProcessor; $this->typeCaster = $typeCaster; @@ -67,6 +74,7 @@ public function __construct( $this->extensionAttributesProcessor = $extensionAttributesProcessor; $this->customAttributesProcessor = $customAttributesProcessor; $this->processors = $processors; + $this->objectKeyMap = $objectKeyMap; } /** @@ -127,7 +135,7 @@ public function buildOutputDataArray($dataObject, $dataObjectType) } } - $outputData[$key] = $value; + $outputData[$this->mapObjectKey($key, ltrim($dataObjectType, '\\'))] = $value; } $outputData = $this->changeOutputArray($dataObject, $outputData); @@ -152,4 +160,20 @@ private function changeOutputArray($dataObject, array $outputData): array return $outputData; } + + /** + * @param string $key + * @param string $dataObjectType + * @return string + */ + protected function mapObjectKey(string $key, string $dataObjectType): string + { + if ( + array_key_exists($dataObjectType, $this->objectKeyMap) && + array_key_exists($key, $this->objectKeyMap[$dataObjectType]) + ) { + $key = $this->objectKeyMap[$dataObjectType][$key]; + } + return $key; + } }