title: Object serialization to json, certain fields only
body: <p>I have a large nested object. I want to serialise this object in the JSON string, however I need only certain fields to be included. Problem here is that fields could change very frequently and I want to build it in a way that could help me easy include or exclude fields for serialisation. </p>
  
  <p>I know that I can write a lot of code to extract certain fields and build JSON "manually". But I wonder if there are any other elegant way to achieve similar outcome but specifying a list of required fields? </p>
  
  <p>For example having following object structure I want include only <code>id</code> and <code>name</code> in the response:</p>
  
  <pre><code>class Building {
      private List&lt;Flat&gt; flats;
  }
  
  class Flat {
      private Integer id;     
      private Person owner;
  }
  
  
  class Person {
      private String name;
      private String surname;
  }
  </code></pre>
  
  <p>Json:</p>
  
  <pre><code>{
      "flats" : [
          {
              "flat":
              {
                  "id" : "1",
                  "person" : {
                      "name" : "John"
                  }
              }
          }
      ]
  }
  </code></pre>