From af6b0f7f61308b311d7fd44f5d90ffd4d0114aa3 Mon Sep 17 00:00:00 2001 From: dittmar Date: Tue, 27 Feb 2024 10:38:06 +0100 Subject: [PATCH] fix enum json serialization, deserialization missing --- src/cadenzaanalytics/cadenza_analytics_extension_service.py | 2 +- src/cadenzaanalytics/data/attribute_role.py | 3 +++ src/cadenzaanalytics/data/data_object.py | 2 +- src/cadenzaanalytics/data/data_type.py | 3 +++ src/cadenzaanalytics/data/extension_type.py | 3 +++ src/cadenzaanalytics/data/geometry_type.py | 3 +++ src/cadenzaanalytics/data/measure_aggregation.py | 3 +++ src/cadenzaanalytics/data/parameter_type.py | 3 +++ src/cadenzaanalytics/response/error_response.py | 2 +- src/cadenzaanalytics/response/extension_data_response.py | 2 +- 10 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/cadenzaanalytics/cadenza_analytics_extension_service.py b/src/cadenzaanalytics/cadenza_analytics_extension_service.py index c67824d..ca06297 100644 --- a/src/cadenzaanalytics/cadenza_analytics_extension_service.py +++ b/src/cadenzaanalytics/cadenza_analytics_extension_service.py @@ -41,4 +41,4 @@ def _list_extensions(self): 'extensionPrintName': extension.print_name, 'extensionType': extension.extension_type}) - return Response(response=json.dumps(result_dict), status=200, mimetype="application/json") + return Response(response=json.dumps(result_dict, default=str), status=200, mimetype="application/json") diff --git a/src/cadenzaanalytics/data/attribute_role.py b/src/cadenzaanalytics/data/attribute_role.py index 31642a4..e1cb0af 100644 --- a/src/cadenzaanalytics/data/attribute_role.py +++ b/src/cadenzaanalytics/data/attribute_role.py @@ -4,3 +4,6 @@ class AttributeRole(Enum): DIMENSION = "dimension" MEASURE = "measure" + + def __str__(self): + return self.value diff --git a/src/cadenzaanalytics/data/data_object.py b/src/cadenzaanalytics/data/data_object.py index 89780f3..97693f5 100644 --- a/src/cadenzaanalytics/data/data_object.py +++ b/src/cadenzaanalytics/data/data_object.py @@ -28,7 +28,7 @@ def _to_dict(self) -> dict: return result def to_json(self, indent=None) -> str: - return json.dumps(self._to_dict(), indent=indent) + return json.dumps(self._to_dict(), indent=indent, default=str) @classmethod def _from_dict(cls, data: dict): diff --git a/src/cadenzaanalytics/data/data_type.py b/src/cadenzaanalytics/data/data_type.py index 743eb98..a7d8e23 100644 --- a/src/cadenzaanalytics/data/data_type.py +++ b/src/cadenzaanalytics/data/data_type.py @@ -8,3 +8,6 @@ class DataType(Enum): FLOAT64 = "float64" ZONEDDATETIME = "zonedDateTime" GEOMETRY = "geometry" + + def __str__(self): + return self.value diff --git a/src/cadenzaanalytics/data/extension_type.py b/src/cadenzaanalytics/data/extension_type.py index 170808e..5967fa4 100644 --- a/src/cadenzaanalytics/data/extension_type.py +++ b/src/cadenzaanalytics/data/extension_type.py @@ -5,3 +5,6 @@ class ExtensionType(Enum): VISUALIZATION = "visualization" ENRICHMENT = "enrichment" CALCULATION = "calculation" + + def __str__(self): + return self.value diff --git a/src/cadenzaanalytics/data/geometry_type.py b/src/cadenzaanalytics/data/geometry_type.py index b696057..7fe0b43 100644 --- a/src/cadenzaanalytics/data/geometry_type.py +++ b/src/cadenzaanalytics/data/geometry_type.py @@ -8,3 +8,6 @@ class GeometryType(Enum): MULTIPOINT = "multipoint" MULTILINESTRING = "multilinestring" MULTIPOLYGON = "multipolygon" + + def __str__(self): + return self.value diff --git a/src/cadenzaanalytics/data/measure_aggregation.py b/src/cadenzaanalytics/data/measure_aggregation.py index 5531fc8..7d587db 100644 --- a/src/cadenzaanalytics/data/measure_aggregation.py +++ b/src/cadenzaanalytics/data/measure_aggregation.py @@ -8,3 +8,6 @@ class MeasureAggregation(Enum): AVERAGE = "average" MIN = "min" MAX = "max" + + def __str__(self): + return self.value diff --git a/src/cadenzaanalytics/data/parameter_type.py b/src/cadenzaanalytics/data/parameter_type.py index 35e169e..4c7a9fb 100644 --- a/src/cadenzaanalytics/data/parameter_type.py +++ b/src/cadenzaanalytics/data/parameter_type.py @@ -9,3 +9,6 @@ class ParameterType(Enum): GEOMETRY = "geometry" SELECT = "select" BOOLEAN = "boolean" + + def __str__(self): + return self.value diff --git a/src/cadenzaanalytics/response/error_response.py b/src/cadenzaanalytics/response/error_response.py index d6b4212..f4d741d 100644 --- a/src/cadenzaanalytics/response/error_response.py +++ b/src/cadenzaanalytics/response/error_response.py @@ -18,7 +18,7 @@ def _get_response_json(self, message: str): "message": message } - return json.dumps(error_message) + return json.dumps(error_message, default=str) def _create_response(self, message: str): return Response(response=self._get_response_json(message), status=self._status, mimetype="application/json") diff --git a/src/cadenzaanalytics/response/extension_data_response.py b/src/cadenzaanalytics/response/extension_data_response.py index 92e2156..f015982 100644 --- a/src/cadenzaanalytics/response/extension_data_response.py +++ b/src/cadenzaanalytics/response/extension_data_response.py @@ -23,7 +23,7 @@ def _get_response_metadata(self, column_metadata): ] } - return json.dumps(metadata) + return json.dumps(metadata, default=str) def _create_response(self, data, column_metadata=None): multipart_response = MultipartEncoder(