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), ]
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, }
class FactType(Schema): SCHEMA = [ Field("name"), Field("id"), ]