code: public static String objectToJson(Object item, Map<String, Object> optionalArgs)
      {
          try
          {
              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              JsonWriter writer = new JsonWriter(stream, optionalArgs);
              writer.write(item);
              writer.close();
              return new String(stream.toByteArray(), "UTF-8");
          }
          catch (Exception e)
          {
              throw new JsonIoException("Unable to convert object to JSON", e);
          }
      }
docs: Convert a Java Object to a JSON String.
  
  @param item Object to convert to a JSON String.
  @param optionalArgs (optional) Map of extra arguments indicating how dates are formatted,
  what fields are written out (optional).  For Date parameters, use the public static
  DATE_TIME key, and then use the ISO_DATE or ISO_DATE_TIME indicators.  Or you can specify
  your own custom SimpleDateFormat String, or you can associate a SimpleDateFormat object,
  in which case it will be used.  This setting is for both java.util.Date and java.sql.Date.
  If the DATE_FORMAT key is not used, then dates will be formatted as longs.  This long can
  be turned back into a date by using 'new Date(longValue)'.
  @return String containing JSON representation of passed in object root.