[Serializer] Handle circular references. symfony/symfony#12098.

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | symfony/symfony#12098
| Applies to    | 2.6 or 2.7
| Fixed tickets | n/a

The same applies to some of the lines below.