Skip to content

Commit

Permalink
[Mime] Fix serializing uninitialized RawMessage::$message to null
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jan 30, 2024
1 parent c2b504e commit 02acd86
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Normalizer/MimeMessageNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Mime\Header\UnstructuredHeader;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\Part\AbstractPart;
use Symfony\Component\Mime\RawMessage;
use Symfony\Component\Serializer\SerializerAwareInterface;
use Symfony\Component\Serializer\SerializerInterface;

Expand Down Expand Up @@ -63,15 +64,18 @@ public function normalize($object, ?string $format = null, array $context = [])
return $ret;
}

$ret = $this->normalizer->normalize($object, $format, $context);

if ($object instanceof AbstractPart) {
$ret = $this->normalizer->normalize($object, $format, $context);
$ret['class'] = \get_class($object);
unset($ret['seekable'], $ret['cid'], $ret['handle']);
}

return $ret;
if ($object instanceof RawMessage && \array_key_exists('message', $ret) && null === $ret['message']) {
unset($ret['message']);
}

return $this->normalizer->normalize($object, $format, $context);
return $ret;
}

/**
Expand Down

0 comments on commit 02acd86

Please sign in to comment.