File tree Expand file tree Collapse file tree 1 file changed +4
-0
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +4
-0
lines changed
Original file line number Diff line number Diff line change 17
17
use ApiPlatform \Core \DataProvider \PaginatorInterface ;
18
18
use ApiPlatform \Core \DataProvider \PartialPaginatorInterface ;
19
19
use ApiPlatform \Core \Metadata \Resource \Factory \ResourceMetadataFactoryInterface ;
20
+ use Symfony \Component \Serializer \Normalizer \AbstractObjectNormalizer ;
20
21
use Symfony \Component \Serializer \Normalizer \CacheableSupportsMethodInterface ;
21
22
use Symfony \Component \Serializer \Normalizer \NormalizerAwareInterface ;
22
23
use Symfony \Component \Serializer \Normalizer \NormalizerAwareTrait ;
@@ -74,6 +75,9 @@ public function hasCacheableSupportsMethod(): bool
74
75
public function normalize ($ object , $ format = null , array $ context = [])
75
76
{
76
77
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
+ }
77
81
return $ this ->normalizeRawCollection ($ object , $ format , $ context );
78
82
}
79
83
You can’t perform that action at this time.
0 commit comments