private static void setFieldType(Class<?> type, PropertyDescriptor propertyDescriptor, FieldInfo fieldInfo) {
    if (type.isEnum()) {
      fieldInfo.setEntityType(FieldType.ENUM);
      fieldInfo.setEntity(type);
      return;
    }
    FieldType fieldType = getFieldType(type);

    if (fieldType == null) {
      if (isArray(type)) {
        fieldInfo.setIsArray(true);
        fieldInfo.addWrapperType(FieldType.ARRAY);
        setFieldType(type.getComponentType(), propertyDescriptor, fieldInfo);
      }
      if (fieldInfo.getEntity() == null) {
        fieldInfo.setEntity(type);
      }
      return;
    }

    if (fieldType == FieldType.LIST || fieldType == FieldType.SET) {
      fieldInfo.addWrapperType(fieldType);
      fieldInfo.setIsArray(true);
      unwrapEntity(getEnclosedParamType(propertyDescriptor.getWriteMethod()), fieldInfo);
    }

    if (fieldType == FieldType.OPTIONAL) {
      fieldInfo.addWrapperType(fieldType);
      unwrapEntity(getEnclosedParamType(propertyDescriptor.getWriteMethod()), fieldInfo);
    }

    if (fieldInfo.getEntity() == null) {
      fieldInfo.setEntity(type);
      fieldInfo.setEntityType(fieldType);
    }
  }