Field | R Documentation |
Basic field from which other fields should extend
It applies no formatting by default, and should only be used in cases where data does not need to be formatted before being serialized or deserialized. On error, the name of the field will be returned.
staypuft::FieldABC
-> Field
class_name
(character) xxx
CHECK_ATTRIBUTE
(logical) default: TRUE
creation_index
(integer) xxx
default
a class, default: Missing
attribute
(character) xxx
data_key
(character) xxx
validate
xxx
required
(logical) xxx
allow_none
(logical) xxx
load_only
(logical) xxx
dump_only
(logical) xxx
missing
(logical) xxx
metadata
Extra arguments to be stored as metadata.
error_messages
(list) xxx
validators
(list) xxx
new()
Create a new Field object
Field$new( default = miss_ing, attribute = NULL, data_key = NULL, validate = NULL, required = FALSE, allow_none = NULL, load_only = FALSE, dump_only = FALSE, missing = miss_ing, error_messages = NULL )
default
If set, this value will be used during serialization if the input value is missing. If not set, the field will be excluded from the serialized output if the input value is missing. May be a value or a callable.
attribute
The name of the key to get the value from when
deserializing. If None
, assumes the key has the same name as the
field.
data_key
The name of the key to get the value from when
deserializing. If None
, assumes the key has the same name as the field.
validate
Validator or collection of validators that
are called during deserialization. Validator takes a field's input
value as its only parameter and returns a boolean. If it returns FALSE
,
an ValidationError
is raised.
required
Raise a ValidationError
if the field value
is not supplied during deserialization.
allow_none
Set this to TRUE
if None
should be considered a
valid value during validation/deserialization. If missing=NULL
and allow_none
is unset, will default to TRUE
. Otherwise, the
default is FALSE
.
load_only
If TRUE
skip this field during serialization,
otherwise its value will be present in the serialized data.
dump_only
If TRUE
skip this field during deserialization,
otherwise its value will be present in the deserialized object. In the
context of an HTTP API, this effectively marks the field as "read-only".
missing
Default deserialization value for the field if the field is not found in the input data. May be a value or a callable.
error_messages
Overrides for Field.default_error_messages
.
A new Field
object
print()
print method for Field objects
Field$print(x, ...)
x
self
...
ignored
get_value()
Return the value for a given key from an object.
Field$get_value(obj, attr, accessor = NULL, default = miss_ing)
obj
The object to get the value from
attr
The attribute/key in obj
to get the value from.
accessor
(callback) A callable used to retrieve the value of attr
default
If set, this value will be used during serialization if
the input value is missing. If not set, the field will be excluded from
the serialized output if the input value is missing. May be a value or
a callable.
from the object obj
. Defaults to marshmallow.utils.get_value
.
validate_()
Perform validation on value
. Raise a ValidationError
if validation does not succeed.
Field$validate_(value)
value
a value
fail()
A helper method that simply raises a
ValidationError
Field$fail(key)
key
a key
validate_missing_()
Validate missing values. Raise a ValidationError
if value
should be considered missing.
Field$validate_missing_(value)
value
a value
serialize()
Pulls the value for the given key from the object, applies the field's formatting and returns the result.
Field$serialize(attr, obj, accessor = NULL)
attr
(character) The attribute or key to get from the object.
obj
(character) The object to pull the key from.
accessor
(callback) Function used to pull values from obj
.
raise ValidationError: In case of formatting problem
xxxx
deserialize()
Deserialize value
.
Field$deserialize(value, attr = NULL, data = NULL, ...)
value
The value to be deserialized.
attr
(character) The attribute/key in data
to be deserialized.
data
(list) The raw input data passed to the Schema.load
.
raise ValidationError: If an invalid value is passed or if a required value is missing.
bind_to_schema()
Update field with values from its parent schema.
Field$bind_to_schema(field_name, schema)
field_name
(character) Field name set in schema.
schema
Parent schema.
serialize_()
Serializes value
to a basic Python datatype. Noop by
default. Concrete :class:Field
classes should implement this method.
Field$serialize_(value, attr = NULL, obj = NULL)
value
The value to be deserialized.
attr
(character) The attribute/key in data
to be deserialized.
obj
(character) The object to pull the key from.
raise ValidationError: In case of formatting or validation failure.
The serialized value
deserialize_()
Deserialize value. Concrete :class:Field
classes should implement this method.
Field$deserialize_(value, attr, data)
value
The value to be deserialized.
attr
(character) The attribute/key in data
to be deserialized.
data
(list) The raw input data passed to the Schema.load
.
raise ValidationError: In case of formatting or validation failure.
The deserialized value
context()
The context dictionary for the parent Schema
Field$context()
root()
Reference to the Schema
that this field belongs
to even if it is buried in a List
Field$root()
None
for unbound fields
clone()
The objects of this class are cloneable with this method.
Field$clone(deep = FALSE)
deep
Whether to make a deep clone.
x <- fields$field() x x$error_messages z <- fields$character() z z$error_messages z$serialize(attr = "foo", obj = list(foo = "bar")) z$deserialize("foo") z$deserialize(fields$missing()) x <- Schema$new("x", cow = fields$character(data_key = "stuff")) x x$fields$cow$data_key if (interactive()) x$load(list(cow = 5)) x$load(list(stuff = 5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.