code: public byte[] toJsonBytes(final Object resource) throws UnsupportedEncodingException {
          if (resource instanceof JSONObject) {
              final JSONObject json = (JSONObject) resource;
              return json.toString().getBytes("UTF-8");
          }
  
          final HashMap<String, Object> out = new HashMap<String, Object>();
          final JSONObject res = beanSerialize(resource, out);
          if (res == null || res.length() == 0) {
              return new JSONObject(out).toString().getBytes("UTF-8");
          } else {
              return res.toString().getBytes("UTF-8");
          }
      }
docs: /*
  The age old json.org library in Android doesn't support
  mapping bean-style objects directly to JSON, so we have
  to call this from a more recent version of JSONObject that
  we include in our jar.