42
42
use Symfony \Component \Serializer \Normalizer \AbstractObjectNormalizer ;
43
43
use Symfony \Component \Serializer \Normalizer \DenormalizerInterface ;
44
44
use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
45
- use Symfony \Component \Serializer \Serializer ;
46
45
47
46
/**
48
47
* Base item normalizer.
@@ -224,9 +223,32 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
224
223
try {
225
224
return $ this ->iriConverter ->getResourceFromIri ($ data , $ context + ['fetch_data ' => true ]);
226
225
} 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
+ );
228
239
} 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
+ );
230
252
}
231
253
}
232
254
@@ -577,7 +599,8 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
577
599
if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
578
600
throw new UnexpectedValueException ($ e ->getMessage (), $ e ->getCode (), $ e );
579
601
}
580
- $ context ['not_normalizable_value_exceptions ' ][] = NotNormalizableValueException::createForUnexpectedDataType (
602
+
603
+ throw NotNormalizableValueException::createForUnexpectedDataType (
581
604
$ e ->getMessage (),
582
605
$ value ,
583
606
[$ className ],
@@ -586,13 +609,12 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
586
609
$ e ->getCode (),
587
610
$ e
588
611
);
589
-
590
- return null ;
591
612
} catch (InvalidArgumentException $ e ) {
592
613
if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
593
614
throw new UnexpectedValueException (\sprintf ('Invalid IRI "%s". ' , $ value ), $ e ->getCode (), $ e );
594
615
}
595
- $ context ['not_normalizable_value_exceptions ' ][] = NotNormalizableValueException::createForUnexpectedDataType (
616
+
617
+ throw NotNormalizableValueException::createForUnexpectedDataType (
596
618
$ e ->getMessage (),
597
619
$ value ,
598
620
[$ className ],
@@ -601,8 +623,6 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
601
623
$ e ->getCode (),
602
624
$ e
603
625
);
604
-
605
- return null ;
606
626
}
607
627
}
608
628
0 commit comments