4242use Symfony \Component \Serializer \Normalizer \AbstractObjectNormalizer ;
4343use Symfony \Component \Serializer \Normalizer \DenormalizerInterface ;
4444use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
45- use Symfony \Component \Serializer \Serializer ;
4645
4746/**
4847 * Base item normalizer.
@@ -224,9 +223,32 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
224223 try {
225224 return $ this ->iriConverter ->getResourceFromIri ($ data , $ context + ['fetch_data ' => true ]);
226225 } catch (ItemNotFoundException $ e ) {
227- throw new UnexpectedValueException ($ e ->getMessage (), $ e ->getCode (), $ e );
226+ if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
227+ throw new UnexpectedValueException ($ e ->getMessage (), $ e ->getCode (), $ e );
228+ }
229+
230+ throw NotNormalizableValueException::createForUnexpectedDataType (
231+ \sprintf ('The type of the "%s" resource "string" (IRI), "%s" given. ' , $ resourceClass , \gettype ($ data )),
232+ $ data ,
233+ [$ resourceClass ],
234+ $ context ['deserialization_path ' ] ?? null ,
235+ true ,
236+ $ e ->getCode (),
237+ $ e
238+ );
228239 } catch (InvalidArgumentException $ e ) {
229- throw new UnexpectedValueException (\sprintf ('Invalid IRI "%s". ' , $ data ), $ e ->getCode (), $ e );
240+ if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
241+ throw new UnexpectedValueException (\sprintf ('Invalid IRI "%s". ' , $ data ), $ e ->getCode (), $ e );
242+ }
243+
244+ throw NotNormalizableValueException::createForUnexpectedDataType (
245+ \sprintf ('The type of the "%s" resource "string" (IRI), "%s" given. ' , $ resourceClass , \gettype ($ data )),
246+ $ data , [$ resourceClass ],
247+ $ context ['deserialization_path ' ] ?? null ,
248+ true ,
249+ $ e ->getCode (),
250+ $ e
251+ );
230252 }
231253 }
232254
@@ -577,7 +599,8 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
577599 if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
578600 throw new UnexpectedValueException ($ e ->getMessage (), $ e ->getCode (), $ e );
579601 }
580- $ context ['not_normalizable_value_exceptions ' ][] = NotNormalizableValueException::createForUnexpectedDataType (
602+
603+ throw NotNormalizableValueException::createForUnexpectedDataType (
581604 $ e ->getMessage (),
582605 $ value ,
583606 [$ className ],
@@ -586,13 +609,12 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
586609 $ e ->getCode (),
587610 $ e
588611 );
589-
590- return null ;
591612 } catch (InvalidArgumentException $ e ) {
592613 if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
593614 throw new UnexpectedValueException (\sprintf ('Invalid IRI "%s". ' , $ value ), $ e ->getCode (), $ e );
594615 }
595- $ context ['not_normalizable_value_exceptions ' ][] = NotNormalizableValueException::createForUnexpectedDataType (
616+
617+ throw NotNormalizableValueException::createForUnexpectedDataType (
596618 $ e ->getMessage (),
597619 $ value ,
598620 [$ className ],
@@ -601,8 +623,6 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
601623 $ e ->getCode (),
602624 $ e
603625 );
604-
605- return null ;
606626 }
607627 }
608628
0 commit comments