DictRField
Resource field for storing JSON-like dictionaries.
DictRField stores dictionary data with automatic JSON serialization and validation. It only supports JSON-compatible values: primitives (str, int, float, bool, None), nested dictionaries, and lists of these types.
The field automatically: - Converts Python objects to JSON-compatible format using str() - Replaces NaN and Inf values with None - Validates that values are dictionaries - Provides an empty dict {} as default if no default_value is specified
This is useful for: - Storing metadata and configuration - Nested structured data - API responses and JSON data - Key-value mappings
Storage behavior: - Stored in KV_STORE by default (inherited from PrimitiveRField) - Not included in dict views by default (can be changed) - Automatically serialized to JSON on save - Automatically deserialized from JSON on load
Example: ```python class MyResource(Resource): # Simple metadata dictionary metadata = DictRField()
# With default value
config = DictRField(default_value={'key': 'value'})
# Included in dict view
summary = DictRField(include_in_dict_view=True)
# Usage
resource = MyResource()
resource.metadata = {'author': 'John', 'version': 1}
resource.config['new_key'] = 'new_value'
```
Note: - Non-JSON-compatible objects are converted to strings - NaN and Inf are replaced with None for JSON compatibility - Nested structures must also be JSON-compatible
include_in_dict_view: boolstorage: RFieldStoragevalidator: ValidatorInitialize a DictRField for storing JSON-like dictionaries.
dict | Nonebool - FalseDeserialize and validate a value from storage.
Validates the stored value using the field's validator before returning it.
AnyAnyGet the default value for this field.
Returns an empty dictionary if no default value was specified. If a default value was provided, it is converted to JSON format to ensure compatibility.
AnySerialize the dictionary value for storage.
Converts the dictionary to JSON-compatible format by: - Converting non-JSON objects to strings - Replacing NaN and Inf with None - Ensuring nested structures are JSON-compatible
AnyAny