From 73fbf1eef34c6139128d8baea87dd9ae4ab539d9 Mon Sep 17 00:00:00 2001
From: Bastien Abadie <abadie@teklia.com>
Date: Thu, 20 May 2021 14:32:52 +0200
Subject: [PATCH] Support dict & list through json

---
 arkindex/documents/export/__init__.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/arkindex/documents/export/__init__.py b/arkindex/documents/export/__init__.py
index f14d16ca03..7f5207d141 100644
--- a/arkindex/documents/export/__init__.py
+++ b/arkindex/documents/export/__init__.py
@@ -1,3 +1,4 @@
+import json
 import logging
 import sqlite3
 import tempfile
@@ -50,13 +51,19 @@ def save_sqlite(rows, table, cursor):
     """
     Write a chunk of rows into an SQLite table
     """
+    def _serialize(value):
+        # Serialize UUID as string
+        if isinstance(value, uuid.UUID):
+            return str(value)
+
+        # Serialize list and dicts as json
+        if isinstance(value, (list, dict)):
+            return json.dumps(value)
+
+        return value
 
-    # Serialize UUID and lists as strings
     rows = [
-        [
-            str(value) if isinstance(value, (uuid.UUID, list)) else value
-            for value in row
-        ]
+        list(map(_serialize, row))
         for row in rows
     ]
 
-- 
GitLab