LP1824391 Hatch set (file write) 'bare' option
authorBill Erickson <berickxx@gmail.com>
Fri, 12 Apr 2019 19:23:38 +0000 (15:23 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 23 May 2019 21:37:35 +0000 (17:37 -0400)
Adds a "bare" option to the hatch "set" command indicating to Hatch the
string content should be written as-is instead of encoded as JSON first.
This essentially gives Hatch a text/plain print-to-file option.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
src/org/evergreen_ils/hatch/RequestHandler.java

index 9fcd24d..fa89dfa 100644 (file)
@@ -155,8 +155,14 @@ public class RequestHandler extends Thread {
             case "set" :
                 key = request.getString("key");
 
-                // JSON-ify the thing stored under "content"
-                String json = JSONObject.valueToString(request.get("content"));
+                String json;
+                if (request.optBoolean("bare", false)) {
+                    // Bare strings are stored as-is, no JSON.
+                    json = request.getString("content");
+                } else {
+                    // JSON-ify the thing stored under "content"
+                    json = JSONObject.valueToString(request.get("content"));
+                }
 
                 if (!fileIO.set(key, json)) {
                     response.put("status", 500);