I am trying to serialize and deserialize a Doctrine object graph.
The structure is pretty complex, but this example sums up my problem:
There is a Company
entity with a OneToMany relationship to Employee
.
The Employee
entity has a ManyToOne relationship with the Company
.
This is serialized as follows:
{
"company": {
"name": "MegaCorp",
"employees": [{
"name": "John Doe",
"company": null
}]
}
}
So it null
s the reference to the Employee
's parent Company
. For serialization this is ok.
But now when I deserialize this json, I get a null
Company
in the Employee
object. What I want (and expect) is to get a correct reference to the parent Company
.
Is this possible using JMS serializer and if so, how can it be done?
If it is not possible, what could be a good workaround? Remember that it is a large graph, I don't want to do it manually.
@preSerialize
and@postSerialize
hooks. So it's doable. – GordonMaxDepth()
? – kero