diff --git a/openedx_events/event_bus/avro/custom_serializers.py b/openedx_events/event_bus/avro/custom_serializers.py index 37a8a150..0ce6bf41 100644 --- a/openedx_events/event_bus/avro/custom_serializers.py +++ b/openedx_events/event_bus/avro/custom_serializers.py @@ -5,6 +5,7 @@ from abc import ABC, abstractmethod from datetime import datetime +from ccx_keys.locator import CCXLocator from opaque_keys.edx.keys import CourseKey, UsageKey from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2 @@ -49,6 +50,25 @@ def deserialize(data: str): return CourseKey.from_string(data) +class CcxCourseLocatorAvroSerializer(BaseCustomTypeAvroSerializer): + """ + CustomTypeAvroSerializer for CCXLocator class. + """ + + cls = CCXLocator + field_type = PYTHON_TYPE_TO_AVRO_MAPPING[str] + + @staticmethod + def serialize(obj) -> str: + """Serialize obj into string.""" + return str(obj) + + @staticmethod + def deserialize(data: str): + """Deserialize string into obj.""" + return CCXLocator.from_string(data) + + class DatetimeAvroSerializer(BaseCustomTypeAvroSerializer): """ CustomTypeAvroSerializer for datetime class. @@ -131,6 +151,7 @@ def deserialize(data: str): DEFAULT_CUSTOM_SERIALIZERS = [ CourseKeyAvroSerializer, + CcxCourseLocatorAvroSerializer, DatetimeAvroSerializer, LibraryLocatorV2AvroSerializer, LibraryUsageLocatorV2AvroSerializer,