Exemplo n.º 1
0
class Fact(Schema):
    SCHEMA = [
        Field("type",
              deserializer=FactType,
              serializer=lambda fact_type: fact_type.name),
        Field("value"),
        Field("id", serializer=False),
        Field("timestamp", serializer=False),
        Field("objects",
              default=[],
              serialize_target="bindings",
              deserializer=Object),
    ]
Exemplo n.º 2
0
class Object(Schema):
    SCHEMA = [
        Field("type", deserializer=ObjectType),
        Field("value"),
        Field("id"),
        Field("object", flatten=True),
        Field("direction"),
    ]

    def serialize(self, exclude_empty=True, to_camel_case=True):
        """Custom serializer for Object"""

        return {
            "object": {
                "id": self.id,
                "value": self.value,
                "type": {
                    "id": self.type.name,
                    "name": self.value,
                },
            },
            "direction": self.direction,
        }
Exemplo n.º 3
0
class FactType(Schema):
    SCHEMA = [
        Field("name"),
        Field("id"),
    ]