From 90f5d4ea4ddcded966c09809f3e65a54941a81c8 Mon Sep 17 00:00:00 2001 From: ulrich Date: Tue, 06 Apr 2021 09:00:43 +0000 Subject: [PATCH] Ablageort bearbeiten und loeschen in Arbeit --- 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