| | |
| | | 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; |
| | |
| | | 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]; |
| | |
| | | } |
| | | } |
| | | |
| | | 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(); |