From c629dd79cb5ec6cfabc5b2e49177b275fbaf247f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 2 May 2022 14:01:07 +0200 Subject: [PATCH] fix serialization - deserialization --- .../PrivateCommentEmbeddableNormalizer.php | 18 ++++++++++-------- .../config/services/serializer.yaml | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php index 27e5b21f7..447b8ddf8 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php @@ -27,7 +27,7 @@ class PrivateCommentEmbeddableNormalizer implements NormalizerInterface, Denorma $this->security = $security; } - public function denormalize($data, string $type, ?string $format = null, array $context = []) + public function denormalize($data, string $type, ?string $format = null, array $context = []): PrivateCommentEmbeddable { if (null === $data) { return null; @@ -35,22 +35,24 @@ class PrivateCommentEmbeddableNormalizer implements NormalizerInterface, Denorma $comment = new PrivateCommentEmbeddable(); - $comment->setCommentForUser($this->security->getUser(), $data['privateComment']); + $comment->setCommentForUser($this->security->getUser(), $data); + + return $comment; } - public function supportsDenormalization($data, string $type, ?string $format = null) + public function supportsDenormalization($data, string $type, ?string $format = null): bool { - return $type === CommentEmbeddable::class; + return $type === PrivateCommentEmbeddable::class; } - public function normalize($comment, $format = null, array $contect = []) + public function normalize($comment, $format = null, array $contect = []): string { - return $comment->getComment(); + return $comment->getCommentForUser($this->security->getUser()); } - public function supportsNormalization($data, ?string $format = null) + public function supportsNormalization($data, ?string $format = null): bool { - return $data instanceof CommentEmbeddable; + return $data instanceof PrivateCommentEmbeddable; } } \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/config/services/serializer.yaml b/src/Bundle/ChillMainBundle/config/services/serializer.yaml index 1084dab71..5ec936b6c 100644 --- a/src/Bundle/ChillMainBundle/config/services/serializer.yaml +++ b/src/Bundle/ChillMainBundle/config/services/serializer.yaml @@ -13,4 +13,6 @@ services: Chill\MainBundle\Serializer\Normalizer\PrivateCommentEmbeddableNormalizer: autowire: true autoconfigure: true + tags: + - { name: 'serializer.normalizer', priority: 64 }