Skip to content

Custom Denormalizer are not used anymore when deserializing relation inside Input #7831

@VincentLanglet

Description

@VincentLanglet

API Platform version(s) affected: 4.2.17 or 4.2.18

Related to the fixes (cc @soyuka)
#7779
#7787

With something like

#[ApiResource]
class Locale { private string $id; }

class MyInput { private Locale $locale }

When calling the endpoint with the data ['locale' => 'en'] it's expected to not denormalize the Locale since it's not an IRI.
But I wrote my custom LocaleDenormalizer which basically does $this->entityManager->getRepository(Locale::class)->find($data); and it worked find before the upgrade.

Looking at how it worked,

Now, it use the ItemNormalizer and keep using it for the locale field. But then since this field is a string, it tries to resolve the IRI without calling the denormalizer on it. And I get a Invalid IRI error.

I think rather than always using the iriConverter, the ItemNormalizer should call serializer::normalize on the string value:

  • If a denormalizer has a higher priority it will be used
  • If not, it will fallback on the ItemNormalizer again which already handle string value with the IriConverter the right way.

A fix like #7830

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions