# evennia.web.api.serializers

Serializers in the Django Rest Framework are similar to Forms in normal django. They’re used for transmitting and validating data, both going to clients and coming to the server. However, where forms often contained presentation logic, such as specifying widgets to use for selection, serializers typically leave those decisions in the hands of clients, and are more focused on converting data from the server to JSON (serialization) for a response, and validating and converting JSON data sent from clients to our enpoints into python objects, often django model instances, that we can use (deserialization).

class `evennia.web.api.serializers.``AttributeSerializer`(*args, **kwargs)

  Bases: `rest_framework.serializers.ModelSerializer`

  Serialize Attribute views.

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.typeclasses.attributes.Attribute`

    `fields` = ['db_key', 'db_category', 'db_attrtype', 'value_display', 'db_value']
  static `get_value_display`(obj: evennia.typeclasses.attributes.Attribute) → str

    Gets the string display of an Attribute’s value for serialization :param obj: Attribute being serialized

    Returns

      The Attribute’s value in string format

class `evennia.web.api.serializers.``TagSerializer`(*args, **kwargs)

  Bases: `rest_framework.serializers.ModelSerializer`

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.typeclasses.tags.Tag`

    `fields` = ['db_key', 'db_category', 'db_data', 'db_tagtype']

class `evennia.web.api.serializers.``SimpleObjectDBSerializer`(*args, **kwargs)

  Bases: `rest_framework.serializers.ModelSerializer`

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.objects.objects.DefaultObject`

    `fields` = ['id', 'db_key']

class `evennia.web.api.serializers.``TypeclassSerializerMixin`

  Bases: `object`

  Mixin that contains types shared by typeclasses. A note about tags, aliases, and permissions. You might note that the methods and fields are defined here, but they’re included explicitly in each child class. What gives? It’s a DRF error: serializer method fields which are inherited do not resolve correctly in child classes, and as of this current version (3.11) you must have them in the child classes explicitly to avoid field errors. Similarly, the child classes must contain the attribute serializer explicitly to not have them render PK-related fields.

  `shared_fields` = ['id', 'db_key', 'attributes', 'db_typeclass_path', 'aliases', 'tags', 'permissions']
  static `get_tags`(obj)

    Serializes tags from the object’s Tagshandler :param obj: Typeclassed object being serialized

    Returns

      List of TagSerializer data

  static `get_aliases`(obj)

    Serializes tags from the object’s Aliashandler :param obj: Typeclassed object being serialized

    Returns

      List of TagSerializer data

  static `get_permissions`(obj)

    Serializes tags from the object’s Permissionshandler :param obj: Typeclassed object being serialized

    Returns

      List of TagSerializer data

  static `get_attributes`(obj)

    Serializes attributes from the object’s AttributeHandler :param obj: Typeclassed object being serialized

    Returns

      List of AttributeSerializer data

  static `get_nicks`(obj)

    Serializes attributes from the object’s NicksHandler :param obj: Typeclassed object being serialized

    Returns

      List of AttributeSerializer data

class `evennia.web.api.serializers.``TypeclassListSerializerMixin`

  Bases: `object`

  Shortened serializer for list views.

  `shared_fields` = ['id', 'db_key', 'db_typeclass_path']

class `evennia.web.api.serializers.``ObjectDBSerializer`(*args, **kwargs)

  Bases: `evennia.web.api.serializers.TypeclassSerializerMixin`, `rest_framework.serializers.ModelSerializer`

  Serializing Objects.

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.objects.objects.DefaultObject`

    `fields` = ['db_location', 'db_home', 'contents', 'exits', 'nicks', 'id', 'db_key', 'attributes', 'db_typeclass_path', 'aliases', 'tags', 'permissions']
    `read_only_fields` = ['id']
  static `get_exits`(obj)

    Gets exits for the object :param obj: Object being serialized

    Returns

      List of data from SimpleObjectDBSerializer

  static `get_contents`(obj)

    Gets non-exits for the object :param obj: Object being serialized

    Returns

      List of data from SimpleObjectDBSerializer

class `evennia.web.api.serializers.``ObjectListSerializer`(*args, **kwargs)

  Bases: `evennia.web.api.serializers.TypeclassListSerializerMixin`, `rest_framework.serializers.ModelSerializer`

  Shortened representation for listings.]

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.objects.objects.DefaultObject`

    `fields` = ['db_location', 'db_home', 'id', 'db_key', 'db_typeclass_path']
    `read_only_fields` = ['id']

class `evennia.web.api.serializers.``AccountSerializer`(*args, **kwargs)

  Bases: `evennia.web.api.serializers.TypeclassSerializerMixin`, `rest_framework.serializers.ModelSerializer`

  This uses the DefaultAccount object to have access to the sessions property

  static `get_session_ids`(obj)

    Gets a list of session IDs connected to this Account :param obj: Account we’re grabbing sessions from :type obj: DefaultAccount

    Returns

      List of session IDs

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.accounts.accounts.DefaultAccount`

    `fields` = ['username', 'session_ids', 'nicks', 'id', 'db_key', 'attributes', 'db_typeclass_path', 'aliases', 'tags', 'permissions']
    `read_only_fields` = ['id']

class `evennia.web.api.serializers.``AccountListSerializer`(*args, **kwargs)

  Bases: `evennia.web.api.serializers.TypeclassListSerializerMixin`, `rest_framework.serializers.ModelSerializer`

  A shortened form for listing.

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.accounts.accounts.DefaultAccount`

    `fields` = ['username', 'id', 'db_typeclass_path']
    `read_only_fields` = ['id']

class `evennia.web.api.serializers.``ScriptDBSerializer`(*args, **kwargs)

  Bases: `evennia.web.api.serializers.TypeclassSerializerMixin`, `rest_framework.serializers.ModelSerializer`

  Serializing Account.

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.scripts.models.ScriptDB`

    `fields` = ['db_interval', 'db_persistent', 'db_start_delay', 'db_is_active', 'db_repeats', 'id', 'db_key', 'attributes', 'db_typeclass_path', 'aliases', 'tags', 'permissions']
    `read_only_fields` = ['id']

class `evennia.web.api.serializers.``ScriptListSerializer`(*args, **kwargs)

  Bases: `evennia.web.api.serializers.TypeclassListSerializerMixin`, `rest_framework.serializers.ModelSerializer`

  Shortened form for listing.

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.scripts.models.ScriptDB`

    `fields` = ['db_interval', 'db_persistent', 'db_start_delay', 'db_is_active', 'db_repeats', 'id', 'db_key', 'db_typeclass_path']
    `read_only_fields` = ['id']

class `evennia.web.api.serializers.``HelpSerializer`(*args, **kwargs)

  Bases: `evennia.web.api.serializers.TypeclassSerializerMixin`, `rest_framework.serializers.ModelSerializer`

  Serializers Help entries (not a typeclass).

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.help.models.HelpEntry`

    `fields` = ['id', 'db_key', 'db_help_category', 'db_entrytext', 'db_date_created', 'tags', 'aliases']
    `read_only_fields` = ['id']

class `evennia.web.api.serializers.``HelpListSerializer`(*args, **kwargs)

  Bases: `evennia.web.api.serializers.TypeclassListSerializerMixin`, `rest_framework.serializers.ModelSerializer`

  Shortened form for listings.

  class `Meta`

    Bases: `object`

    `model`

      alias of `evennia.help.models.HelpEntry`

    `fields` = ['id', 'db_key', 'db_help_category', 'db_date_created']
    `read_only_fields` = ['id']