Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization incomplete on JOINED inheritance subclass #2669

Open
antoinenedelecdecathlon opened this issue Mar 21, 2024 · 0 comments
Open

Comments

@antoinenedelecdecathlon
Copy link

antoinenedelecdecathlon commented Mar 21, 2024

API Platform version(s) affected: 3.1.22

Description

I am serializing an object of class foo :

  • GET operation on /foos/1
  • fooGroup normalization context group

My foo class have two ManyToOne attributes:

  • barSingleTable (a class with SINGLE_TABLE InheritanceType)
    • this class contain a x attribute, with the fooGroup for normalization
  • barJoined (a class with JOINED InheritanceType)
    • the main table have two joined entities barJoinedA and barJoinedB
    • both have a respective attribute Y and Zcontaining the fooGroup for normalization

When I fetch /foos/1, here is my payload:

{
    "@context": "/api/contexts/Foo",
    "@id": "/api/foos/1",
    "@type": "Foo",
    "bar_single_table": {
        "@id": "/api/bar_single_tables/1",
        "@type": "BarSingleTable",
        "x": "x_value"
    },
    "bar_joined": "/api/bar_joined_a/1"
}

Here is what I expect:

{
    "@context": "/api/contexts/Foo",
    "@id": "/api/foos/1",
    "@type": "Foo",
    "bar_single_table": {
        "@id": "/api/bar_single_tables/1",
        "@type": "BarSingleTable",
        "x": "x_value"
    },
    "bar_joined": {
        "@id": "/api/bar_joined_a/1",
        "@type": "BarJoinedA",
        "y": "y_value"
    }
}

NB: IF I add the fooGroup group on ANY attribute of the main joined class (let's say the $id), everything works well as intended, and all joined attribute are now serialized :

{
    "@context": "/api/contexts/Foo",
    "@id": "/api/foos/1",
    "@type": "Foo",
    "bar_single_table": {
        "@id": "/api/bar_single_tables/1",
        "@type": "BarSingleTable",
        "x": "x_value"
    },
    "bar_joined": {
        "@id": "/api/bar_joined_a/1",
        "@type": "BarJoinedA",
        "y": "y_value",
        "id": 1
    }
}

Possible Solution
I would think the check for serialization isn't done on the joined entities, but if this check is passed the serialization process is OK.

UPDATE 26/03:

the ApiProperty in SerializerPropertyMetadataFactory->transformLinkStatus function has a builtIn type of the parent DiscriminatorMap class. So I guess this is "logical" that the getClassSerializerGroups does not return all the possible child class groups.

How would a MetadataFactory instanciate an ApiProperty with the correct requested child Discriminator class ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant