Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit de05be2

Browse filesBrowse files
committed
fix: preserve_empty_objects support
1 parent 9f7f1e1 commit de05be2
Copy full SHA for de05be2

File tree

Expand file treeCollapse file tree

1 file changed

+4
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-0
lines changed

‎src/Serializer/AbstractCollectionNormalizer.php

Copy file name to clipboardExpand all lines: src/Serializer/AbstractCollectionNormalizer.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiPlatform\Core\DataProvider\PaginatorInterface;
1818
use ApiPlatform\Core\DataProvider\PartialPaginatorInterface;
1919
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
20+
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
2021
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
2122
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
2223
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
@@ -74,6 +75,9 @@ public function hasCacheableSupportsMethod(): bool
7475
public function normalize($object, $format = null, array $context = [])
7576
{
7677
if (!isset($context['resource_class']) || isset($context['api_sub_level'])) {
78+
if (($context[AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS] ?? false) === true && $object instanceof \Countable && 0 === $object->count()) {
79+
return $object;
80+
}
7781
return $this->normalizeRawCollection($object, $format, $context);
7882
}
7983

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.