title: Modify object serialization depending on what class is being serialized
body: <p>So my goal is to return some objects as the response body from a Spring REST controller. The thing is, these two objects point each other, something kind of like this:</p>
  
  <pre><code>public class Person {
      private Set&lt;Team&gt; teams;
  }
  
  public class Team {
      private Set&lt;Person&gt; members;
  }
  </code></pre>
  
  <p>If I return these two objects from a controllers mapping method right away, the generated response will be infinite and will probably crash the browser, because the members set has people, and each person has a set of teams, and so on, and everything gets returned infinitely.</p>
  
  <p>How can I manage, instead of showing the whole list of, say, members, to display just the name of each of the members?</p>
  
  <p>Any help will be much appreciated, thanks!</p>