4

I have a similar question as JMS Serializer serialize object in object with diffrent view, but I can't get it work like in the accepted answer.

I have a User model that has many Reviews, but the Reviews owner is another User. I have a serialization policy that outputs the following:

{
  "id": "1",
  "name": "John Doe",
  "reviews": [
    {
      "id": "1",
      "rate": "5",
      "evaluator": {
        "id": "2",
        "name": "Alice",
        "reviews": [...]
      }
    }, ...
  ]
}

The behavior makes sense since the associated (Review) owner model is the same as the parent model and therefore it's using the same serialization policy. But how could I define a custom serialization policy for the nested model so outputs me the following:

{
  "id": "1",
  "name": "John Doe",
  "reviews": [
    {
      "id": "1"
      "rate": "5",
      "evaluator": "Alice"
    }, ...
  ]
}
Community
  • 1
  • 1
  • You can use ```max_depth``` http://stackoverflow.com/questions/22590073/jms-serializer-how-to-limit-the-depth-of-serialisation-for-an-object-graph http://jmsyst.com/libs/serializer/master/cookbook/exclusion_strategies – Mohammad Zare Moghadam Jul 25 '16 at 09:19

0 Answers0