Skip to content

Commit e6cd64c

Browse files
author
birkof
committed
Fix normalization output Data Transformer for Json format
1 parent 2944053 commit e6cd64c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Serializer/ItemNormalizer.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2222
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
2323
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
24+
use ApiPlatform\Core\Util\ClassInfoTrait;
2425
use Psr\Log\LoggerInterface;
2526
use Psr\Log\NullLogger;
2627
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
@@ -36,6 +37,8 @@
3637
*/
3738
class ItemNormalizer extends AbstractItemNormalizer
3839
{
40+
use ClassInfoTrait;
41+
3942
private $logger;
4043

4144
public function __construct(PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, IriConverterInterface $iriConverter, ResourceClassResolverInterface $resourceClassResolver, PropertyAccessorInterface $propertyAccessor = null, NameConverterInterface $nameConverter = null, ClassMetadataFactoryInterface $classMetadataFactory = null, ItemDataProviderInterface $itemDataProvider = null, bool $allowPlainIdentifiers = false, LoggerInterface $logger = null, DataTransformerInterface $dataTransformer = null, ResourceMetadataFactoryInterface $resourceMetadataFactory = null, $allowUnmappedClass = false)
@@ -45,6 +48,19 @@ public function __construct(PropertyNameCollectionFactoryInterface $propertyName
4548
$this->logger = $logger ?: new NullLogger();
4649
}
4750

51+
/**
52+
* {@inheritdoc}
53+
*/
54+
public function normalize($object, $format = null, array $context = [])
55+
{
56+
$outputClass = $this->getOutputClass($this->getObjectClass($object), $context);
57+
if (null !== $outputClass && null !== $this->dataTransformer && $this->dataTransformer->supportsTransformation($object, $outputClass, $context)) {
58+
$object = $this->dataTransformer->transform($object, $outputClass, $context);
59+
}
60+
61+
return parent::normalize($object, $format, $context);
62+
}
63+
4864
/**
4965
* {@inheritdoc}
5066
*

0 commit comments

Comments
 (0)