core.bones.json

Module Contents

Classes

JsonBone

This bone saves its content as a JSON-string, but unpacks its content to a dict or list when used.

class core.bones.json.JsonBone(*, indexed=False, multiple=False, languages=None, schema={}, **kwargs)

Bases: viur.core.bones.raw.RawBone

This bone saves its content as a JSON-string, but unpacks its content to a dict or list when used. :param schema If provided we can control and verify which data to accept.

# Example
schema= {"type": "object", "properties" :{"price": {"type": "number"},"name": {"type": "string"}}
# This will only accept the provided JSON when price is a number and name is a string.

Initializes a new Bone.

Parameters:
  • indexed (bool) –

  • multiple (bool) –

  • languages (bool) –

  • schema (Mapping) –

type = 'raw.json'
singleValueSerialize(value, skel, name, parentIndexed)

Serializes a single value of the bone for storage in the database.

Derived bone classes should overwrite this method to implement their own logic for serializing single values. The serialized value should be suitable for storage in the database.

Parameters:
singleValueUnserialize(val)

Unserializes a single value of the bone from the stored database value.

Derived bone classes should overwrite this method to implement their own logic for unserializing single values. The unserialized value should be suitable for use in the application logic.

singleValueFromClient(value, skel, bone_name, client_data)

Load a single value from a client

Parameters:
  • value (str | list | dict) – The single value which should be loaded.

  • skel – The SkeletonInstance where the value should be loaded into.

  • bone_name – The bone name of this bone in the SkeletonInstance.

  • client_data – The data taken from the client, a dictionary with usually bone names as key

Returns:

A tuple. If the value is valid, the first element is the parsed value and the second is None. If the value is invalid or not parseable, the first element is a empty value and the second a list of ReadFromClientError.

structure()

Describes the bone and its settings as an JSON-serializable dict. This function has to be implemented for subsequent, specialized bone types.

Return type:

dict