diff --git a/src/videoag_common/api_object/__init__.py b/src/videoag_common/api_object/__init__.py index 8617f6fb9b936686daf7e40541a9c63bdf62719d..52283cacb686bf3aa81bf89f6975c6bffe1c01f6 100644 --- a/src/videoag_common/api_object/__init__.py +++ b/src/videoag_common/api_object/__init__.py @@ -6,5 +6,6 @@ from .object import ( VisibilityApiObject, api_mapped, api_include_in_data, + NoSerializationContext ) from .object_class import ApiObjectClass diff --git a/src/videoag_common/api_object/object.py b/src/videoag_common/api_object/object.py index 341600b2b0411d3fba1a21c4bbf7553230721acf..bd27778088688d80498b01b9c5b31fef6d513e8c 100644 --- a/src/videoag_common/api_object/object.py +++ b/src/videoag_common/api_object/object.py @@ -37,6 +37,22 @@ def api_include_in_data( return decorator +class NoSerializationContext(dict): + """ + A dict which can be used as a context for serialize() to prevent any serialization of objects of a specific type. + This dict pretends like all keys are already present. Actually retrieving or updating an item throws an error + """ + + def __setitem__(self, __key, __value): + raise Exception("Not supported") + + def __getitem__(self, __key): + raise Exception("Not supported") + + def __contains__(self, __key): + return True + + API_VALUE_OBJECT_CLASSES_BY_ID: dict[str, type["ApiValueObject"]] = {} _disable_value_object_registration = False