title: Java object to JSON with only selected fields
body: <p>I have java class like:</p>
  
  <pre><code>public class Sample{
   int foo=5;
   int bar=6;
  }
  </code></pre>
  
  <p>now I want to generate JSON object but without bar field:</p>
  
  <pre><code>{"foo":5}
  </code></pre>
  
  <p>What is a best way to accomplish that?
  Should I compose JSON string manually, or can I use some library, or generator? </p>