Fixed excpetion that no IRI could be generated if a new Part was created via POST operation via API

This was because the objectSerializer in PartNormalizer messed up the JSONLD IRI generation of the paramaters property. It tried to generate this IRI via the Part ressource class, which is not possible
This commit is contained in:
Jan Böhmer 2024-01-05 23:38:49 +01:00
parent d20b668e87
commit df23ba07ba
3 changed files with 6 additions and 5 deletions

View file

@ -39,6 +39,7 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
/**
* @see \App\Tests\Serializer\PartNormalizerTest
* TODO: Properly rewrite this class to use the SerializerAware interface and dont use the ObjectNormalizer directly
*/
class PartNormalizer implements NormalizerInterface, DenormalizerInterface
{
@ -65,7 +66,8 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface
public function supportsNormalization($data, string $format = null, array $context = []): bool
{
return $data instanceof Part;
//We only remove the type field for CSV export
return $format === 'csv' && $data instanceof Part ;
}
/**
@ -86,8 +88,6 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface
unset($data['type']);
}
$data['total_instock'] = $object->getAmountSum();
return $data;
}