Skip to content

Commit ae0d147

Browse files
authored
Improve the XML serialization of numeric types (#1469)
1 parent 61b376c commit ae0d147

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

src/CodeGenerator/src/Generator/RequestSerializer/RestXmlSerializer.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,12 @@ private function dumpXmlShape(Member $member, Shape $shape, string $output, stri
141141
switch ($shape->getType()) {
142142
case 'blob':
143143
case 'string':
144+
return $this->dumpXmlShapeString($member, $shape, $output, $input);
144145
case 'integer':
145146
case 'long':
146147
case 'float':
147148
case 'double':
148-
return $this->dumpXmlShapeString($member, $shape, $output, $input);
149+
return $this->dumpXmlShapeNumeric($member, $output, $input);
149150
case 'boolean':
150151
return $this->dumpXmlShapeBoolean($member, $output, $input);
151152
}
@@ -230,6 +231,23 @@ private function dumpXmlShapeString(Member $member, Shape $shape, string $output
230231
return strtr($body, $replacements);
231232
}
232233

234+
private function dumpXmlShapeNumeric(Member $member, string $output, string $input): string
235+
{
236+
if ($member instanceof StructureMember && $member->isXmlAttribute()) {
237+
$body = 'OUTPUT->setAttribute(NODE_NAME, (string) INPUT);';
238+
} else {
239+
$body = 'OUTPUT->appendChild($document->createElement(NODE_NAME, (string) INPUT));';
240+
}
241+
242+
$replacements = [
243+
'INPUT' => $input,
244+
'OUTPUT' => $output,
245+
'NODE_NAME' => var_export($member->getLocationName() ?? ($member instanceof StructureMember ? $member->getName() : 'member'), true),
246+
];
247+
248+
return strtr($body, $replacements);
249+
}
250+
233251
private function dumpXmlShapeBoolean(Member $member, string $output, string $input): string
234252
{
235253
if ($member instanceof StructureMember && $member->isXmlAttribute()) {

src/Service/CloudFront/src/ValueObject/Paths.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void
6666
if (null === $v = $this->quantity) {
6767
throw new InvalidArgument(sprintf('Missing parameter "Quantity" for "%s". The value cannot be null.', __CLASS__));
6868
}
69-
$node->appendChild($document->createElement('Quantity', $v));
69+
$node->appendChild($document->createElement('Quantity', (string) $v));
7070
if (null !== $v = $this->items) {
7171
$node->appendChild($nodeList = $document->createElement('Items'));
7272
foreach ($v as $item) {

src/Service/Route53/src/ValueObject/ResourceRecordSet.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void
541541
$node->appendChild($document->createElement('SetIdentifier', $v));
542542
}
543543
if (null !== $v = $this->weight) {
544-
$node->appendChild($document->createElement('Weight', $v));
544+
$node->appendChild($document->createElement('Weight', (string) $v));
545545
}
546546
if (null !== $v = $this->region) {
547547
if (!ResourceRecordSetRegion::exists($v)) {
@@ -564,7 +564,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void
564564
$node->appendChild($document->createElement('MultiValueAnswer', $v ? 'true' : 'false'));
565565
}
566566
if (null !== $v = $this->ttl) {
567-
$node->appendChild($document->createElement('TTL', $v));
567+
$node->appendChild($document->createElement('TTL', (string) $v));
568568
}
569569
if (null !== $v = $this->resourceRecords) {
570570
$node->appendChild($nodeList = $document->createElement('ResourceRecords'));

src/Service/S3/src/ValueObject/CORSRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void
152152
}
153153
}
154154
if (null !== $v = $this->maxAgeSeconds) {
155-
$node->appendChild($document->createElement('MaxAgeSeconds', $v));
155+
$node->appendChild($document->createElement('MaxAgeSeconds', (string) $v));
156156
}
157157
}
158158
}

src/Service/S3/src/ValueObject/CompletedPart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void
139139
$node->appendChild($document->createElement('ChecksumSHA256', $v));
140140
}
141141
if (null !== $v = $this->partNumber) {
142-
$node->appendChild($document->createElement('PartNumber', $v));
142+
$node->appendChild($document->createElement('PartNumber', (string) $v));
143143
}
144144
}
145145
}

0 commit comments

Comments
 (0)