Skip to content

Commit 2c2a8db

Browse files
committed
change normalizer priority
1 parent 2f542d7 commit 2c2a8db

File tree

4 files changed

+45
-67
lines changed

4 files changed

+45
-67
lines changed

composer.lock

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Extensions/EmptyDataDenormalizer.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/Symfony/Extensions/EmptyDataNormalizer.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313
namespace ServiceBus\MessageSerializer\SymfonyNormalizer\Extensions;
1414

15+
use function ServiceBus\Common\createWithoutConstructor;
16+
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
1517
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
1618

1719
/**
1820
* Normalizer for an object without attributes (empty).
1921
*/
20-
final class EmptyDataNormalizer implements NormalizerInterface
22+
final class EmptyDataNormalizer implements NormalizerInterface, DenormalizerInterface
2123
{
2224
/**
2325
* @psalm-var array<string, array<array-key, string>>
@@ -61,4 +63,28 @@ static function(\ReflectionProperty $property): string
6163

6264
return false;
6365
}
66+
67+
/**
68+
* @noinspection MoreThanThreeArgumentsInspection
69+
*
70+
* {@inheritdoc}
71+
*
72+
* @throws \ServiceBus\Common\Exceptions\ReflectionApiException
73+
*/
74+
public function denormalize($data, $class, $format = null, array $context = []): object
75+
{
76+
/** @psalm-var class-string $class */
77+
78+
return createWithoutConstructor($class);
79+
}
80+
81+
/**
82+
* @noinspection MoreThanThreeArgumentsInspection
83+
*
84+
* {@inheritdoc}
85+
*/
86+
public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
87+
{
88+
return empty($data);
89+
}
6490
}

src/Symfony/SymfonyMessageSerializer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use ServiceBus\MessageSerializer\MessageDecoder;
2121
use ServiceBus\MessageSerializer\MessageEncoder;
2222
use ServiceBus\MessageSerializer\Serializer;
23-
use ServiceBus\MessageSerializer\SymfonyNormalizer\Extensions\EmptyDataDenormalizer;
2423
use ServiceBus\MessageSerializer\SymfonyNormalizer\Extensions\EmptyDataNormalizer;
2524
use ServiceBus\MessageSerializer\SymfonyNormalizer\Extensions\PropertyNameConverter;
2625
use ServiceBus\MessageSerializer\SymfonyNormalizer\Extensions\PropertyNormalizerWrapper;
@@ -60,12 +59,11 @@ public function __construct(Serializer $serializer = null, array $normalizers =
6059
new SymfonySerializer\Normalizer\DateTimeNormalizer(['datetime_format' => 'c']),
6160
new SymfonySerializer\Normalizer\ArrayDenormalizer(),
6261
new PropertyNormalizerWrapper(null, new PropertyNameConverter(), new PhpDocExtractor()),
63-
new EmptyDataDenormalizer(),
6462
new EmptyDataNormalizer(),
6563
];
6664

6765
/** @psalm-var array<array-key, (\Symfony\Component\Serializer\Normalizer\NormalizerInterface|\Symfony\Component\Serializer\Normalizer\DenormalizerInterface)> $normalizers */
68-
$normalizers = \array_merge($defaultNormalizers, $normalizers);
66+
$normalizers = \array_merge($normalizers, $defaultNormalizers);
6967

7068
$this->normalizer = new SymfonySerializer\Serializer($normalizers);
7169
$this->serializer = $serializer ?? new JsonSerializer();

0 commit comments

Comments
 (0)