title: How to serialize only a very few properties in a Java class
body: <p>Recently in an interview I was asked a question:</p>
  
  <blockquote>
    <p>There are 100 properties in a Java class and I should be able to serialize only 2 of the properties. How is this possible?</p>
  </blockquote>
  
  <p>Marking all the 98 properties was not the answer as it is not efficient. 
  My answer was to carve out those properties into a separate class and make it serializable. </p>
  
  <p>But I was told that, I will not be allowed to modify the structure of the class.
  Well, I tried to find an answer in online forums, but in vain.</p>