Maybe it is just my misunderstanding of this annotation however it does not seam to work as expected.
I have the following object graph
User
-> C
As of the latest version, using @MaxDepth() annotation and SerializationContext::create()->enableMaxDepthChecks() in the controller does the job.
Because I did not have access to the latest version of the serializer I had to find a workaround to the @MaxDepth. This may also help you.
Use @JMS\ExclusionPolicy("all") on all entities that are connected.
Now use @JMS\Expose only on those properties that you want to have serialize. On join relations only use this annotation in one direction. That will fix your problem.
namespace FinalConcept\TimeTracker\EntitiesBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
/**
* FinalConcept\TimeTracker\EntitiesBundle\Entity
*
* @JMS\ExclusionPolicy("all")
* @ORM\Table(name="users")
* @ORM\Entity(repositoryClass="FinalConcept\TimeTracker\EntitiesBundle\Repository\UserRepository")
*/
class User implements UserInterface, \Serializable
{
/**
* @JMS\Expose
* @ORM\ManyToOne(targetEntity="company", inversedBy="users")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id")
*/
private $company;
}