@@ -63,9 +63,15 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a
6363 // check (line 271). For abstract resource classes with a discriminator map (e.g. Attachment), this
6464 // fails because the array has no _type key. Fix by resolving IRI strings directly.
6565 // See: https://github.com/Part-DB/Part-DB-server/issues/1370
66- if (is_string ($ data )) {
66+ if (is_string ($ data ) || (is_array ($ data ) && isset ($ data ['@id ' ]) && is_string ($ data ['@id ' ]))) {
67+ if (is_array ($ data )) {
68+ $ iri = $ data ['@id ' ];
69+ } else {
70+ $ iri = $ data ;
71+ }
72+
6773 try {
68- return $ this ->iriConverter ->getResourceFromIri ($ data , $ context + ['fetch_data ' => true ]);
74+ return $ this ->iriConverter ->getResourceFromIri ($ iri , $ context + ['fetch_data ' => true ]);
6975 } catch (ItemNotFoundException $ e ) {
7076 if (false === ($ context ['denormalize_throw_on_relation_not_found ' ] ?? true )) {
7177 return null ;
@@ -76,7 +82,7 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a
7682 throw NotNormalizableValueException::createForUnexpectedDataType ($ e ->getMessage (), $ data , [$ type ], $ context ['deserialization_path ' ] ?? null , true , $ e ->getCode (), $ e );
7783 } catch (InvalidArgumentException $ e ) {
7884 if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
79- throw new UnexpectedValueException (sprintf ('Invalid IRI "%s". ' , $ data ), $ e ->getCode (), $ e );
85+ throw new UnexpectedValueException (sprintf ('Invalid IRI "%s". ' , $ iri ), $ e ->getCode (), $ e );
8086 }
8187 throw NotNormalizableValueException::createForUnexpectedDataType (sprintf ('Invalid IRI "%s". ' , $ data ), $ data , [$ type ], $ context ['deserialization_path ' ] ?? null , true , $ e ->getCode (), $ e );
8288 }
0 commit comments