I'm using Symfony 2.8, FOSRestBundle and JMSSerializerBundle.
Discriminator field type
of Document
entity doesn't apear in serialized model when I serialize specific group ("api" group in folowing example) of entity Citizen
.
Document:
namespace MyBundle\Entity;
use JMS\Serializer\Annotation as JMS;
…
/**
* @JMS\Discriminator(field = "type", map = {
* "doc1" = "MyBundle\Entity\Document1",
* "doc2" = "MyBundle\Entity\Document2"
* })
*/
class Document
…
Citizen:
class Citizen
{
…
/**
* @var ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="MyBundle\Entity\Document",
* cascade={ "PERSIST", "REMOVE" },
* orphanRemoval=true,
* mappedBy="citizen"
* )
*
* @JMS\Groups({"api"})
*/
private $documents;
…
{
…
"documents": [
{
"number": "000000",
"date": "01.01.1970",
"serial": "0000",
"place": ""
}
],
…
}
{
…
"documents": [
{
"type": "doc1",
"number": "000000",
"date": "01.01.1970",
"serial": "0000",
"place": ""
}
],
…
}
If I remove specific serialization group, then type
field is present in serialized output.
Thanks in advance
Just found issue on github.
Seems for now, workaround with Default
group is needed, see lordelph's comment