8000 Added support for serializedName alias in properties. Fixed #15171 · acataluddi/symfony@4ed1b22 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ed1b22

Browse files
committed
Added support for serializedName alias in properties. Fixed symfony#15171
1 parent f2590d1 commit 4ed1b22

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public function normalize($object, $format = null, array $context = array())
109109
$attributeValue = $maxDepthHandler($attributeValue, $object, $attribute, $format, $context);
110110
}
111111

112+
// Adding support for serialized-name
113+
array_key_exists($attribute, $attributesMetadata) && $attributesMetadata[$attribute]->getSerializedName() !== null?
114+
$serializedName = $attributesMetadata[$attribute]->getSerializedName():
115+
$serializedName = $attribute;
116+
112117
/**
113118
* @var $callback callable|null
114119
*/
@@ -118,10 +123,10 @@ public function normalize($object, $format = null, array $context = array())
118123
}
119124

120125
if (null !== $attributeValue && !is_scalar($attributeValue)) {
121-
$stack[$attribute] = $attributeValue;
126+
$stack[$serializedName] = $attributeValue;
122127
}
123128

124-
$data = $this->updateData($data, $attribute, $attributeValue, $class, $format, $context);
129+
$data = $this->updateData($data, $serializedName, $attributeValue, $class, $format, $context);
125130
}
126131

127132
foreach ($stack as $attribute => $attributeValue) {

0 commit comments

Comments
 (0)
0