From 085e44001597085b7fd486b49f917d3f55384f11 Mon Sep 17 00:00:00 2001 From: Christian Boettcher <c.boettcher@fz-juelich.de> Date: Mon, 10 May 2021 12:05:07 +0200 Subject: [PATCH] fix json encoding not automatically supported for custom classes --- apiserver/storage/JsonFileStorageAdapter.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apiserver/storage/JsonFileStorageAdapter.py b/apiserver/storage/JsonFileStorageAdapter.py index f6dde1f..97ecef8 100644 --- a/apiserver/storage/JsonFileStorageAdapter.py +++ b/apiserver/storage/JsonFileStorageAdapter.py @@ -12,6 +12,9 @@ class StoredData: actualData: LocationData users: List[str] + def toDict(self): + return {'actualData' : self.actualData.__dict__, 'users' : self.users} + # This stores LocationData via the StoredData Object as json files # These Jsonfiles then contain the actualData, as well as the users with permissions for this LocationData @@ -55,7 +58,7 @@ class JsonFileStorageAdapter(AbstractLocationDataStorageAdapter): toStore.users = [usr] toStore.actualData = data with open(os.path.join(localpath, id), 'w') as json_file: - json.dump(toStore.__dict__, json_file) + json.dump(toStore.toDict(), json_file) return {id : data} def getDetails(self, type: LocationDataType, id: str): @@ -82,7 +85,7 @@ class JsonFileStorageAdapter(AbstractLocationDataStorageAdapter): toStore.actualData = data with open(fullpath, 'w') as file: - json.dump(data.__dict__, file) + json.dump(toStore.toDict(), file) return {id : data} def getOwner(self, type: LocationDataType, id: str): -- GitLab