Skip to content

REST API Associative Array Not Supporting #5659

@jimuldesai

Description

@jimuldesai

Steps to reproduce

  1. Install Magento from develop branch.
  2. Create custom module with API and respond associative array like below
    $response=[];
    $response["price_format''] =[
    "pattern"=> "$%s",
    "precision"=> "2",
    "requiredPrecision"=> "2",
    "decimalSymbol"=> ".",
    "groupSymbol"=> ",",
    "groupLength"=> "3",
    "integerRequired"=> "1"
    ];

Expected result

"price_format": {
"pattern": "$%s",
"precision": "2",
"requiredPrecision": "2",
"decimalSymbol": ".",
"groupSymbol": ",",
"groupLength": "3",
"integerRequired": "1"
}

Actual result

"price_format": [
"$%s",
"2",
"2",
".",
",",
"3",
"1"
]

It can be possible by making small change in class Magento\Framework\Reflection\DataObjectProcessor as below, but unsure if it affect to other API SOAP or in core methods etc.

public function buildOutputDataArray($dataObject, $dataObjectType)
{
.
.
.
.
foreach ($value as $elmKey =>$singleValue) {
if (is_object($singleValue) && !($singleValue instanceof Phrase)) {
$singleValue = $this->buildOutputDataArray($singleValue, $arrayElementType);
}
$valueResult[$elmKey] = $this->typeCaster->castValueToType($singleValue, $arrayElementType)
}
.
.
}

Metadata

Metadata

Assignees

Labels

Component: Framework/WebapiUSE ONLY for FRAMEWORK RELATED BUG! E.g If bug related to Catalog WEB API use just CatalogEvent: distributed-cdDistributed Contribution DayIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions