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

When serializing subentities discriminator value is always added to serialized output #479

Closed
johnpez opened this issue Aug 20, 2015 · 1 comment

Comments

@johnpez
Copy link

johnpez commented Aug 20, 2015

I have an abstract parent entity with several sub entities. The discriminator column is called "type". No matter what, when serializing these sub entities, the "type" column is added to the output, even though it isn't a property that I can access on the entity, thus I can't get rid of it.

I've solved through a rather roundabout method of overriding GenericSerializationVisitor (via overriding JsonSerializationVisitor) and adding a method "removeData".

public function removeData($key){
    if (isset($this->data[$key])) unset($this->data[$key]);
}

Then, I have a listener function set up on post_serialize of my sub entities, in which I call

public function postSerializeSubEntity(ObjectEvent $event)
{
    $event->getVisitor()->removeData('type');
}

Hope this is helpful to someone else. If there is a better way of solving this issue that I missed please let me know!

@goetas
Copy link
Collaborator

goetas commented Apr 3, 2017

sorry for the incredibly long feedback loop.
you can put the "type" in a non existent group. see "groups" option on @discriminator annotation

@goetas goetas closed this as completed Apr 3, 2017
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

2 participants