| 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
defaulta class, default: Missing
attribute(character) xxx
data_key(character) xxx
validatexxx
required(logical) xxx
allow_none(logical) xxx
load_only(logical) xxx
dump_only(logical) xxx
missing(logical) xxx
metadataExtra 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 )
defaultIf 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.
attributeThe name of the key to get the value from when
deserializing. If None, assumes the key has the same name as the
field.
data_keyThe name of the key to get the value from when
deserializing. If None, assumes the key has the same name as the field.
validateValidator 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.
requiredRaise a ValidationError if the field value
is not supplied during deserialization.
allow_noneSet 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_onlyIf TRUE skip this field during serialization,
otherwise its value will be present in the serialized data.
dump_onlyIf 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".
missingDefault deserialization value for the field if the field is not found in the input data. May be a value or a callable.
error_messagesOverrides for Field.default_error_messages.
A new Field object
print()print method for Field objects
Field$print(x, ...)
xself
...ignored
get_value()Return the value for a given key from an object.
Field$get_value(obj, attr, accessor = NULL, default = miss_ing)
objThe object to get the value from
attrThe attribute/key in obj to get the value from.
accessor(callback) A callable used to retrieve the value of attr
defaultIf 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)
valuea value
fail()A helper method that simply raises a
ValidationError
Field$fail(key)
keya key
validate_missing_()Validate missing values. Raise a ValidationError
if value should be considered missing.
Field$validate_missing_(value)
valuea 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, ...)
valueThe 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.
schemaParent 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)
valueThe 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)
valueThe 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)
deepWhether 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.