Skip to content

Serializer docs refer to nonexistent method #10250

Closed
@mattattui

Description

@mattattui

I've been following along with the Serializing interfaces and abstract classes section of the Serializer docs, and got to this example (line 1234 in the current master source):

$discriminator = new ClassDiscriminatorFromClassMetadata($classMetadataFactory);
$discriminator->addClassMapping(CodeRepository::class, new ClassDiscriminatorMapping('type', [
    'github' => GitHubCodeRepository::class,
    'bitbucket' => BitBucketCodeRepository::class,
]));

Unfortunately ClassDiscriminatorFromClassMetadata doesn't appear to have an addClassMapping() method in either version 4.1, or master. In fact I can't find a method called addClassMapping anywhere in the Serializer component, which is a shame because it looks like a really useful feature :)

If someone could tell me how to add a mapping to the class discriminator in the symfony framework, I'm happy to work up a PR to correct the code example (fyi: I don't think I can use the much easier-looking annotation-based method in the example below it because I think I need to dynamically add the class mapping during a compiler pass based on a configuration. The use-case is that I'm developing a bundle that provides an abstract entity that users can extend, and I need to be able to deserialize API data into objects of those user-supplied classes).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions