@@ -243,9 +243,33 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
243
243
try {
244
244
return $ this ->iriConverter ->getResourceFromIri ($ data , $ context + ['fetch_data ' => true ]);
245
245
} catch (ItemNotFoundException $ e ) {
246
- throw new UnexpectedValueException ($ e ->getMessage (), $ e ->getCode (), $ e );
246
+ if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
247
+ throw new UnexpectedValueException ($ e ->getMessage (), $ e ->getCode (), $ e );
248
+ }
249
+
250
+ throw NotNormalizableValueException::createForUnexpectedDataType (
251
+ \sprintf ('The type of the "%s" resource "string" (IRI), "%s" given. ' , $ resourceClass , \gettype ($ data )),
252
+ $ data ,
253
+ [$ resourceClass ],
254
+ $ context ['deserialization_path ' ] ?? null ,
255
+ true ,
256
+ $ e ->getCode (),
257
+ $ e
258
+ );
247
259
} catch (InvalidArgumentException $ e ) {
248
- throw new UnexpectedValueException (\sprintf ('Invalid IRI "%s". ' , $ data ), $ e ->getCode (), $ e );
260
+ if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
261
+ throw new UnexpectedValueException (\sprintf ('Invalid IRI "%s". ' , $ data ), $ e ->getCode (), $ e );
262
+ }
263
+
264
+ throw NotNormalizableValueException::createForUnexpectedDataType (
265
+ \sprintf ('The type of the "%s" resource "string" (IRI), "%s" given. ' , $ resourceClass , \gettype ($ data )),
266
+ $ data ,
267
+ [$ resourceClass ],
268
+ $ context ['deserialization_path ' ] ?? null ,
269
+ true ,
270
+ $ e ->getCode (),
271
+ $ e
272
+ );
249
273
}
250
274
}
251
275
0 commit comments