code: @Override
      void writeBean(Bean bean, Class<?> declaredType, RootType rootTypeFlag) throws IOException {
          Ref ref = references.getReferences().get(bean);
          if (ref != null) {
              if (ref.hasBeenSerialized) {
                  output.writePositiveExtensionInt(MsgPack.JODA_TYPE_REF, ref.position);
                  return;
              }
              output.writeMapHeader(1);
              output.writePositiveExtensionInt(MsgPack.JODA_TYPE_REF_KEY, ref.position);
          }
  
          ClassInfo classInfo = references.getClassInfo(bean.getClass());
          MetaProperty<?>[] props = classInfo.metaProperties;
          int count = props.length;
          Object[] values = new Object[count];
          int size = 0;
          for (MetaProperty<?> prop : props) {
              Object value = SerOptional.extractValue(prop, bean);
              values[size++] = value;
          }
  
          if (rootTypeFlag == RootType.ROOT_WITH_TYPE || (rootTypeFlag == RootType.NOT_ROOT && bean.getClass() != declaredType)) {
              output.writeArrayHeader(size + 1);
              output.writePositiveExtensionInt(MsgPack.JODA_TYPE_BEAN, classInfo.position);
          } else {
              output.writeArrayHeader(size);
          }
  
          for (int i = 0; i < size; i++) {
              MetaProperty<?> prop = props[i];
              Object value = values[i];
  
              Class<?> propType = SerOptional.extractType(prop, bean.getClass());
  
              if (value == null) {
                  output.writeNil();
                  continue;
              }
  
              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);
                  }
              }
          }
          if (ref != null) {
              ref.sent();
          }
      }
docs: -----------------------------------------------------------------------