Last night, my web app died with white screen being returned to a user. It didn't take very long to find out the root case: PHP
was running out of memory.
After tracing the problem, I concluded that JMS Serializer
failed to handle serialization loop.
I have class ProductGroup
which has number of Product
objects (list). Now, each Product
refers to a group that it belongs to. So, when user tries to serialize ProductGroup
, it does that, then proceeds to serialize each Product
when it jumps back to ProductGroup
(which was just serialized) effectively creating a serialization loop.
I managed to fix that but putting @Exclude
on Product::group
property.
So, the question is : Do I have another option when it comes to serializing? Is it possible that JMS Serializer
is not capable of figuring out the loop?
You could try setting MaxDepth
on ProductGroup->products and Product->group to ensure it won't go into a loop. Also using your approach with different serialization groups for groups + product and product + group could mitigate this and ensure that you can still have the associated group when fetching a single product.
Regarding your second question, having a references in both directions is even discouraged in Doctrine, so JMS\\Serializer throwing some kind of Exception instead of trying to "fix" it seems like expected behaviour.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.