title: Java How to convert a GenericRecord to a json string?
body: <p>I am trying to convert a GenericRecord to a json string so I can pass it to something like a JSONObject. I am thinking about using the JsonEncoder to do this. Right now I have something like:</p>
  
  <pre><code>ByteArrayOutputStream out = new ByteArrayOutputStream();
  JsonEncoder jsonEncoder = new JsonEncoder(genericRecord.getSchema(),out);
  </code></pre>
  
  <p>However it's giving me an error:</p>
  
  <pre><code>error: incompatible types: ByteArrayOutputStream cannot be converted to JsonGenerator
  </code></pre>
  
  <p>Per the source code of JsonEncoder it should have a construct that takes in a outputstream so I am not sure why I am getting this error.
  Can someone suggest how to fix the problem? Any other suggestion on how to convert a GenericRecord to a json string is also welcome. Thanks!</p>