code: private void writeBean(Bean bean, Class<?> declaredType, RootType rootTypeFlag) throws IOException {
          output.writeObjectStart();
          // type information
          if (rootTypeFlag == RootType.ROOT_WITH_TYPE || (rootTypeFlag == RootType.NOT_ROOT && bean.getClass() != declaredType)) {
              String typeStr = SerTypeMapper.encodeType(bean.getClass(), settings, basePackage, knownTypes);
              if (rootTypeFlag == RootType.ROOT_WITH_TYPE) {
                  basePackage = bean.getClass().getPackage().getName() + ".";
              }
              output.writeObjectKeyValue(BEAN, typeStr);
          }
          // property information
          for (MetaProperty<?> prop : bean.metaBean().metaPropertyIterable()) {
              if (prop.style().isSerializable() || (prop.style().isDerived() && settings.isIncludeDerived())) {
                  Object value = SerOptional.extractValue(prop, bean);
                  if (value != null) {
                      output.writeObjectKey(prop.name());
                      Class<?> propType = SerOptional.extractType(prop, bean.getClass());
                      if (value instanceof Bean) {
                          if (settings.getConverter().isConvertible(value.getClass())) {
                              writeSimple(propType, value);
                          } else {
                              writeBean((Bean) value, propType, RootType.NOT_ROOT);
                          }
                      } else {
                          SerIterator itemIterator = settings.getIteratorFactory().create(value, prop, bean.getClass());
                          if (itemIterator != null) {
                              writeElements(itemIterator);
                          } else {
                              writeSimple(propType, value);
                          }
                      }
                  }
              }
          }
          output.writeObjectEnd();
      }
docs: write a bean as a JSON object