class Entity(JsonObject): """ A base class for the object model """ oid = Property("oid", type=str) created = Property("created", default=datetime.now)
class Parent(JsonObject): __add_type_identifier__ = False field1 = Property(type=str, allow_none=False, description="some field 1") field2 = Property(type=str, allow_none=False, description="some field 2") field3 = Property(type=str, allow_none=False, description="some field 3", schema_ref="http://schemas.org/fieldtype#") keys = Property(default=dict, type=MapOf(Child))
class Company(Entity): """ This class represents a company. """ company_name = Property("company-name", type=str) description = Property("description", type=str) def __init__(self, **kwargs): super(Company, self).__init__(**kwargs) # I use this field only for checking that the field "description" # is accessed from the getter instead of using default accessor. self._used_getter = False def get_description(self): # Set _used_getter to True if this getter has been called. self._used_getter = True return self._description
class TestObject(JsonObject): date_time = Property("date-time", handler=DateTimeHandler(), default=datetime.now) def __init__(self, **kwargs): JsonObject.__init__(self, **kwargs) self._deserialized = False def _after_deserialize(self): self._deserialized = True
class TestObject1(JsonObject): field1 = Property() def get_field2(self): return self._field2 def set_field2(self, field2): self._field2 = field2 field2 = property(get_field2, set_field2) def update_field2(self, val): self.field2 = val
class TestObject(JsonObject): prop1 = Property() def __init__(self, **kwargs): super().__init__(**kwargs) self._prop2 = None def set_prop2(self, prop2): self._prop2 = prop2 def get_prop2(self): return self._prop2 prop2 = property(get_prop2, set_prop2)
class TestObject2(JsonObject): some_boolean_1 = Property(handler=bool_handler) some_boolean_2 = Property(handler=bool_handler) some_boolean_3 = Property(handler=bool_handler)
class Customer(JsonObject): first_name = Property(json="first-name") last_name = Property(json="last-name") tax_id = Property(json="tax-id")
class ListOfInts(JsonObject): __jsonpickle_format__ = True values = Property()
class JsonPickleInvoice(JsonObject): __jsonpickle_format__ = True customer = Property(type=Customer) items = Property(type=ArrayOf(Item))
class Child(JsonObject): property1 = Property()
class Child(JsonObject): __add_type_identifier__ = False field1 = Property(type=str)
class TestObject(JsonObject): val = Property(type=Enum1, enum_as_str=True)
class Type2(JsonObject): field_1 = Property(type=int, title="Field 1 title") field_2 = Property(type=Values, enum_as_str=True) field_3 = Property(type=str, pattern=".*") field_4 = Property(type=str, format="email")
class Type1(JsonObject): field_1 = Property(type=str) field_2 = Property(type=Type2)
class Item(JsonObject): field = Property(schema=field_schema)
class TestObject(JsonObject): property1 = Property()
class Parent(JsonObject): children = Property(type=ArrayOf(Child))
class TestAliasedObject(JsonObject): field1 = Property()
class TestObject5(JsonObject): field1 = Property(group="group1") field2 = Property(group="group2") field3 = Property(group="group2")
class TestObject4(JsonObject): val1 = Property() val2 = Property()
class ValidatorTest(JsonObject): __validate__ = True field_1 = Property(type=str, allow_none=False, validator="default")
class TestObject(JsonObject): val = Property(type=Enum1)
class Sector(Entity): employees = Property("employees", default=[])
class TestObject(JsonObject): __jsonpickle_format__ = True prop1 = Property()
class Employee(Entity): name = Property()
class ValidatorTest2(JsonObject): __validate__ = True email = Property(validator=EmailValidator())
class Item(JsonObject): product_id = Property(json="product-id") quantity = Property() unit_price = Property("unit-price")
class TestObject(JsonObject): field1 = Property(default=1) field2 = Property(default=True) field3 = Property(default=False) field4 = Property(default=dict) field5 = Property(default=lambda: [1, 2, 3])
class Invoice(JsonObject): number = Property() datetime = Property() customer = Property(type=Customer) items = Property(type=ArrayOf(Item))