From a43e1a055018aab9590c88c45d8495f99bfb6254 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Mon, 05 Apr 2021 18:39:49 +0000
Subject: [PATCH] Ablageort-Liste

---
 src/de/uhilger/mediaz/api/StorageHandler.java |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/de/uhilger/mediaz/api/StorageHandler.java b/src/de/uhilger/mediaz/api/StorageHandler.java
index 024900b..8de56fd 100644
--- a/src/de/uhilger/mediaz/api/StorageHandler.java
+++ b/src/de/uhilger/mediaz/api/StorageHandler.java
@@ -18,6 +18,7 @@
 package de.uhilger.mediaz.api;
 
 import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
 import com.sun.net.httpserver.HttpExchange;
 import com.sun.net.httpserver.HttpHandler;
 import de.uhilger.mediaz.App;
@@ -169,8 +170,7 @@
       String type = elems[elems.length - 1];
       logger.info(type);
       List list = fs.list(type);
-      Gson gson = new Gson();
-      return gson.toJson(list);
+      return jsonWithEnclosingType(list);
     } else {
       String type = elems[elems.length - 2];
       String elemName = elems[elems.length - 1];
@@ -178,6 +178,17 @@
     }
   }
   
+  private String jsonWithEnclosingType(Object o) {
+    StringBuilder sb = new StringBuilder();
+    sb.append("{\"");
+    sb.append(o.getClass().getSimpleName());
+    sb.append("\": ");
+    Gson gson = new Gson();
+    sb.append(gson.toJson(o));
+    sb.append("}");
+    return sb.toString();
+  }
+  
   
   private String bodyLesen(HttpExchange e) throws IOException {
     InputStream is = e.getRequestBody();

--
Gitblit v1.9.3