Open andreaslarssen opened 9 years ago
+1
+1
+1
Still no update on that issue? For my part, if I add some fields on your "Question" entity, they will appear in the serialized content, but the ones from subclasses remain hidden. Removing the "@Type" annotation solves the issue but I do not think this is what we want.
In GraphNavigator, changing line 93 to this fixes it too (Still ugly because it does not use Discriminator Map):
if (null === $type OR ('object' === gettype($data) AND 'array' !== $type['name'] AND (new \ReflectionClass($type['name']))->isAbstract())) {
Or before "default" in switch line 282 you can enable loading discriminator value from VirtualProperty:
case is_object($data)
&& !empty($metadata->propertyMetadata[$metadata->discriminatorFieldName])
&& $metadata->propertyMetadata[$metadata->discriminatorFieldName] instanceof VirtualPropertyMetadata:
$typeValue = (string) $data->{$metadata->propertyMetadata[$metadata->discriminatorFieldName]->getter}();
break;
nb: in this same switch you can notice that without this fix the discriminator has to be a "public" property of the class, since accessors are not used... Even though a "public" property would not work either.
I'm using the Serlalizer Bundle with Symfony2, but suspect this is a Serializer issue.
I have an abstract class "Question":
...extended by three sub classes, using this yml annotation file (Example for the "SingleChoice" extended class).
The abstract class "Question" is used by my "Survey" class, which holds an ArrayCollection of Questions.
When serializing a survey
...this is the output
Are anyone else seeing this kind of behavior? Am I doing something wrong?