|
22 | 22 | use JMS\Serializer\Exception\RuntimeException; |
23 | 23 | use JMS\Serializer\Metadata\ClassMetadata; |
24 | 24 | use JMS\Serializer\Metadata\PropertyMetadata; |
| 25 | +use JMS\Serializer\Naming\AdvancedNamingStrategyInterface; |
25 | 26 | use JMS\Serializer\Naming\PropertyNamingStrategyInterface; |
26 | 27 |
|
27 | 28 | /** |
@@ -49,7 +50,7 @@ class XmlSerializationVisitor extends AbstractVisitor |
49 | 50 | /** @var boolean */ |
50 | 51 | private $formatOutput; |
51 | 52 |
|
52 | | - public function __construct(PropertyNamingStrategyInterface $namingStrategy, AccessorStrategyInterface $accessorStrategy = null) |
| 53 | + public function __construct($namingStrategy, AccessorStrategyInterface $accessorStrategy = null) |
53 | 54 | { |
54 | 55 | parent::__construct($namingStrategy, $accessorStrategy); |
55 | 56 | $this->objectMetadataStack = new \SplStack; |
@@ -244,7 +245,11 @@ public function visitProperty(PropertyMetadata $metadata, $object, Context $cont |
244 | 245 | if (!$node instanceof \DOMCharacterData) { |
245 | 246 | throw new RuntimeException(sprintf('Unsupported value for XML attribute for %s. Expected character data, but got %s.', $metadata->name, json_encode($v))); |
246 | 247 | } |
247 | | - $attributeName = $this->namingStrategy->translateName($metadata); |
| 248 | + if ($this->namingStrategy instanceof AdvancedNamingStrategyInterface) { |
| 249 | + $attributeName = $this->namingStrategy->getPropertyName($metadata, $context); |
| 250 | + } else { |
| 251 | + $attributeName = $this->namingStrategy->translateName($metadata); |
| 252 | + } |
248 | 253 | $this->setAttributeOnNode($this->currentNode, $attributeName, $node->nodeValue, $metadata->xmlNamespace); |
249 | 254 |
|
250 | 255 | return; |
@@ -293,7 +298,11 @@ public function visitProperty(PropertyMetadata $metadata, $object, Context $cont |
293 | 298 | } |
294 | 299 |
|
295 | 300 | if ($addEnclosingElement = !$this->isInLineCollection($metadata) && !$metadata->inline) { |
296 | | - $elementName = $this->namingStrategy->translateName($metadata); |
| 301 | + if ($this->namingStrategy instanceof AdvancedNamingStrategyInterface) { |
| 302 | + $elementName = $this->namingStrategy->getPropertyName($metadata, $context); |
| 303 | + } else { |
| 304 | + $elementName = $this->namingStrategy->translateName($metadata); |
| 305 | + } |
297 | 306 |
|
298 | 307 | $namespace = null !== $metadata->xmlNamespace |
299 | 308 | ? $metadata->xmlNamespace |
|
0 commit comments