As @sergey-fedotov suggested, you need a custom implementation.
Give the code below a try:
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class StdClassNormalizer implements NormalizerInterface
{
public function normalize($object, string $format = null, array $context = []): array|\stdClass
{
if ($object instanceof \stdClass && empty(get_object_vars($object))) {
return new \stdClass();
}
return (array) $object;
}
public function supportsNormalization($data, string $format = null, array $context = []): bool
{
return $data instanceof \stdClass;
}
}
Don't forget to register StdClassNormalizer
as a Service.