@param Schema $field_schema
@param null|boolean|int|float|string|array $default_value
@returns null|boolean|int|float|string|array

@throws Exception if $field_schema type is unknown.
195801
public function read_default_value(Schema $field_schema, $default_value)
    {
        switch ($field_schema->type()) {
            case Schema::NULL_TYPE:
                return null;
            case Schema::BOOLEAN_TYPE:
                return $default_value;
            case Schema::INT_TYPE:
            case Schema::LONG_TYPE:
                return (int)$default_value;
            case Schema::FLOAT_TYPE:
            case Schema::DOUBLE_TYPE:
                return (float)$default_value;
            case Schema::STRING_TYPE:
            case Schema::BYTES_TYPE:
                return $default_value;
            case Schema::ARRAY_SCHEMA:
                $array = array();
                foreach ($default_value as $json_val) {
                    $val = $this->read_default_value($field_schema->items(), $json_val);
                    $array [] = $val;
                }
                return $array;
            case Schema::MAP_SCHEMA:
                $map = array();
                foreach ($default_value as $key => $json_val)
                    $map[$key] = $this->read_default_value($field_schema->values(),
                        $json_val);
                return $map;
            case Schema::UNION_SCHEMA:
                return $this->read_default_value($field_schema->schema_by_index(0),
                    $default_value);
            case Schema::ENUM_SCHEMA:
            case Schema::FIXED_SCHEMA:
                return $default_value;
            case Schema::RECORD_SCHEMA:
                $record = array();
                foreach ($field_schema->fields() as $field) {
                    $field_name = $field->name();
                    if (!$json_val = $default_value[$field_name])
                        $json_val = $field->default_value();

                    $record[$field_name] = $this->read_default_value($field->type(),
                        $json_val);
                }
                return $record;
            default:
                throw new Exception(sprintf('Unknown type: %s', $field_schema->type()));
        }
    }
964741
private function completeFieldDefaultValue(Input $field, ReflectionParameter $param, string $fieldName): void
    {
        if (!$field->hasDefaultValue() && $param->isDefaultValueAvailable()) {
            $field->setDefaultValue($param->getDefaultValue());
        }

        if (!$field->hasDefaultValue()) {
            $defaultValue = $this->getPropertyDefaultValue($fieldName);
            if ($defaultValue !== null) {
                $field->setDefaultValue($defaultValue);
            }
        }
    }
183641
public function extractDefault(ColumnSchema $field, $defaultValue)
    {
        if (strncmp($field->dbType, 'bit', 3) === 0) {
            $field->defaultValue = bindec(trim($defaultValue, 'b\''));
        } else {
            parent::extractDefault($field, $defaultValue);
        }
    }
312276
private SchemaType getSchemaType(Class returnType) {
        SchemaType schemaType = null;
        if (XmlObject.class.isAssignableFrom(returnType)) {
            try {
                Field f = returnType.getField("type");
                if (SchemaType.class.isAssignableFrom(f.getType()) && Modifier.isStatic(f.getModifiers())) {
                    schemaType = (SchemaType) f.get(null);
                }
            } catch (NoSuchFieldException x) {
            } catch (IllegalAccessException x) {
            }
        }
        return schemaType;
    }
520579
protected Field convertFieldSchema(Schema inputSchema, Field field, WorkUnitState workUnit)
      throws SchemaConversionException {
    if (field.name().equals(payloadField)) {
      // Create a payload field with latest schema
      return createLatestPayloadField(field);
    }
    // Make a copy of the field to the output schema
    return new Field(field.name(), field.schema(), field.doc(), field.defaultValue(), field.order());
  }
867790
public function __fieldFix()
    {
        $schema = $this->getClassSchema();
        foreach ($this->__calculateSaveDownRows() as $column) {
            if (!isset($schema[$column]['type'])) {
                throw new Exception("No type hinting/docblock found for '{$column}' in '" . get_called_class() . "'.", E_USER_WARNING);
            }

            $type = $schema[$column]['type'];
            if ($type == "integer" && !is_int($this->$column)) {
                $this->$column = intval($this->$column);
            }
        }
        return true;
    }
1153592
def get_field(self, schema):
        
        type = schema.get_type(self.schema_type)
        logger.debug('Found schema type %s; base type %s, restricted values %s' % \
                     (self.schema_type, type.base_type(), type.restricted_values))
        kwargs = {}
        if type.restricted_values:
            # field has a restriction with enumerated values - pass as choices to field
            # - empty value at beginning of list for unset value; for required fields,
            #   will force user to select a value, rather than first item being default
            choices = []
            choices.extend(type.restricted_values)
            # restricted values could include a blank
            # if it's there, remove it so we don't get two
            if '' in choices:
                choices.remove('')
            choices.insert(0, '')   # add blank choice at the beginning of the list
            kwargs['choices'] = choices

        # TODO: possibly also useful to look for pattern restrictions

        basetype = type.base_type()
        if basetype == 'string':
            newfield = StringField(self.xpath, required=self.required, **kwargs)
            # copy original creation counter to newly created field
            # to preserve declaration order
            newfield.creation_counter = self.creation_counter
            return newfield
        else:
            raise Exception("basetype %s is not yet supported by SchemaField" % basetype)
1321340
function getDefaultValue (res) {
  if (res.body) {
    return res.body;
  }
  else if (res.swagger.schema) {
    return res.swagger.schema.default || res.swagger.schema.example;
  }
}
526574
public function getDefaultClause($xmldb_field) {

        $defaultvalue = $this->getDefaultValue ($xmldb_field);

        if ($defaultvalue !== null) {
            return ' DEFAULT ' . $defaultvalue;
        } else {
            return null;
        }
    }
311166
protected function applyDefaultValues(&$value, $schema, $path)
    {
        // only apply defaults if feature is enabled
        if (!$this->factory->getConfig(self::CHECK_MODE_APPLY_DEFAULTS)) {
            return;
        }

        // apply defaults if appropriate
        $requiredOnly = $this->factory->getConfig(self::CHECK_MODE_ONLY_REQUIRED_DEFAULTS);
        if (isset($schema->properties) && LooseTypeCheck::isObject($value)) {
            // $value is an object or assoc array, and properties are defined - treat as an object
            foreach ($schema->properties as $currentProperty => $propertyDefinition) {
                $propertyDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($propertyDefinition);
                if (
                    !LooseTypeCheck::propertyExists($value, $currentProperty)
                    && property_exists($propertyDefinition, 'default')
                    && $this->shouldApplyDefaultValue($requiredOnly, $propertyDefinition, $currentProperty, $schema)
                ) {
                    // assign default value
                    if (is_object($propertyDefinition->default)) {
                        LooseTypeCheck::propertySet($value, $currentProperty, clone $propertyDefinition->default);
                    } else {
                        LooseTypeCheck::propertySet($value, $currentProperty, $propertyDefinition->default);
                    }
                    $this->appliedDefaults[] = $currentProperty;
                }
            }
        } elseif (isset($schema->items) && LooseTypeCheck::isArray($value)) {
            $items = array();
            if (LooseTypeCheck::isArray($schema->items)) {
                $items = $schema->items;
            } elseif (isset($schema->minItems) && count($value) < $schema->minItems) {
                $items = array_fill(count($value), $schema->minItems - count($value), $schema->items);
            }
            // $value is an array, and items are defined - treat as plain array
            foreach ($items as $currentItem => $itemDefinition) {
                $itemDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($itemDefinition);
                if (
                    !array_key_exists($currentItem, $value)
                    && property_exists($itemDefinition, 'default')
                    && $this->shouldApplyDefaultValue($requiredOnly, $itemDefinition)) {
                    if (is_object($itemDefinition->default)) {
                        $value[$currentItem] = clone $itemDefinition->default;
                    } else {
                        $value[$currentItem] = $itemDefinition->default;
                    }
                }
                $path->setFromDefault();
            }
        } elseif (
            $value instanceof self
            && property_exists($schema, 'default')
            && $this->shouldApplyDefaultValue($requiredOnly, $schema)) {
            // $value is a leaf, not a container - apply the default directly
            $value = is_object($schema->default) ? clone $schema->default : $schema->default;
            $path->setFromDefault();
        }
    }
992929
private function determineSchema($mix_schema)
    {
        if(null === $mix_schema) {
            $mix_schema = $this->buildSchema();
        }
        if ($mix_schema instanceof Schema) {
            return $mix_schema;
        }
        if (is_string($mix_schema)) {
            return new Schema($mix_schema);
        }
        throw new \Exception('You must provide a Schema or Kind. Alternatively, you can extend GDS\Store and implement the buildSchema() method.');
    }
920206
protected function prepare_value( $value, $schema ) {
		switch ( $schema['type'] ) {
			case 'string':
				return (string) $value;
			case 'number':
				return (float) $value;
			case 'boolean':
				return (bool) $value;
			default:
				return null;
		}
	}
1214315
@Override
	public void addType(int pos, Class<? extends Value> type) throws ConflictingFieldTypeInfoException {
		if (pos == schema.size()) {
			// right at the end, most common case
			schema.add(type);
		} else if (pos < schema.size()) {
			// in the middle, check for existing conflicts
			Class<? extends Value> previous = schema.get(pos);
			if (previous == null) {
				schema.set(pos, type);
			} else if (previous != type) {
				throw new ConflictingFieldTypeInfoException(pos, previous, type);
			}
		} else {
			// grow to the end
			for (int i = schema.size(); i <= pos; i++) {
				schema.add(null);
			}
			schema.set(pos, type);
		}
	}
948990
protected function validateNullType($value, array $schema): ErrorResult
    {
        $result = new ErrorResult();
        if ($value !== null) {
            $result->addError($this->createError('type=NULL', 'type=' . gettype($value)));
        }
        return $result;
    }
929088
def _normalize_default_setter(self, mapping, schema, field):
        
        if 'default_setter' in schema[field]:
            setter = schema[field]['default_setter']
            if isinstance(setter, _str_type):
                setter = self.__get_rule_handler('normalize_default_setter',
                                                 setter)
            mapping[field] = setter(mapping)
1155265
protected function getFieldValue($field)
    {
        if (is_string($field)) {
            if (!isset($this->allFields[$field])) {
                throw new ApplicationException(Lang::get(
                    'backend::lang.form.missing_definition',
                    compact('field')
                ));
            }

            $field = $this->allFields[$field];
        }

        $defaultValue = !$this->model->exists
            ? $field->getDefaultFromData($this->data)
            : null;

        return $field->getValueFromData(
            $this->data, 
            is_string($defaultValue) ? trans($defaultValue) : $defaultValue
        );
    }
465122
void setValue(int parameterIndex, PreparedStatement preparedStatement,
			Class<?> fieldType, Object fieldValue) throws Exception {

		try {

			if (fieldType == String.class) {
				preparedStatement
						.setString(parameterIndex, (String) fieldValue);
			} else if (fieldType == java.sql.Timestamp.class) {
				preparedStatement.setTimestamp(parameterIndex,
						(java.sql.Timestamp) fieldValue);
			} else if (fieldType == java.sql.Date.class) {
				preparedStatement.setDate(parameterIndex,
						(java.sql.Date) fieldValue);
			} else if (fieldType == java.sql.Time.class) {
				preparedStatement.setTime(parameterIndex,
						(java.sql.Time) fieldValue);
			} else if (fieldType == boolean.class || fieldType == Boolean.class) {

				if (fieldValue != null) {
					boolean boolValue = (boolean) (Boolean) fieldValue;
					preparedStatement.setInt(parameterIndex,
							(boolValue ? 1 : 0));
				} else {
					preparedStatement.setInt(parameterIndex, 0);

				}
			} else if (fieldType == int.class || fieldType == Integer.class) {

				if (fieldValue != null) {
					preparedStatement.setInt(parameterIndex,
							(int) (Integer) fieldValue);
				} else {
					preparedStatement.setNull(parameterIndex,
							java.sql.Types.INTEGER);
				}
			} else if (fieldType == long.class || fieldType == Long.class) {

				if (fieldValue != null) {
					preparedStatement.setLong(parameterIndex,
							(long) (Long) fieldValue);
				} else {
					preparedStatement.setNull(parameterIndex,
							java.sql.Types.INTEGER);
				}
			} else if (fieldType == float.class || fieldType == Float.class) {

				if (fieldValue != null) {
					preparedStatement.setFloat(parameterIndex,
							(float) (Float) fieldValue);
				} else {
					preparedStatement.setNull(parameterIndex,
							java.sql.Types.FLOAT);
				}

			} else if (fieldType == double.class || fieldType == Double.class) {

				if (fieldValue != null) {
					preparedStatement.setDouble(parameterIndex,
							(double) (Double) fieldValue);
				} else {
					preparedStatement.setNull(parameterIndex,
							java.sql.Types.DOUBLE);
				}

			} else {
				final String msg = "Unknown data type. type=" + fieldType
						+ " value=" + fieldValue;
				loge(msg);
				throw new RuntimeException(msg);
			}
		} catch (Exception e) {
			loge("#setValue", e);
			throw e;
		}

	}