protected void writeHeaders(Object obj, OutputStream stream) throws IOException {
    while (obj instanceof Iterable) {
      Iterator itr = ((Iterable) obj).iterator();
      if (!itr.hasNext()) {
        return;
      }
      obj = itr.next();
    }

    while (obj != null && obj.getClass().isArray()) {
      if (Array.getLength(obj) == 0) {
        return;
      }
      obj = Array.get(obj, 0);
    }

    if (obj == null) {
      return;
    }

    Class objClass = obj.getClass();

    final PojoAttributeMapping attributeMapping = _config.getAttributeMapping(objClass);
    if (attributeMapping != null) {
      if (_config.isWriteHeaders()) {
        writeHeaders(stream, attributeMapping, "");
        writeRaw(stream, NEWLINE);
      }

      prepareGetters(objClass, _config.getAttributeMapping(objClass));
    }
  }
  public void serialize(Object obj, OutputStream stream) throws IOException {
    if (_config.isWriteHeaders()) {
      writeHeaders(obj, stream);
    }

    if (obj != null) {
      final PojoAttributeMapping pojoAttributeMapping = _config.getAttributeMapping(obj.getClass());

      writeContent(obj, stream, true, pojoAttributeMapping, true);
    }
  }