title: Java Springboot: Return only some attributs of an object
body: <p>Assuming the following class:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Foo {
    String a, b, c, d;
  
    // The rest of the class...
  }
  </code></pre>
  
  <p>And a REST API controller using Springboot:</p>
  
  <pre class="lang-java prettyprint-override"><code>@GetMapping("/foo")
  public Foo myFuntion() {
      return new Foo(...);
  }
  </code></pre>
  
  <p>Requesting <code>/foo</code> return this JSON:</p>
  
  <pre><code>{
   "a": "...",
   "b": "...",
   "c": "...",
   "d": "..."
  }
  </code></pre>
  
  <p>However, I would like to return only some attributes of the <code>Foo</code> class, for example, only attributes <code>a</code> and <code>b</code>.</p>
  
  <p>How could I do that without creating a new class?</p>