LP1824391 Hatch set (file write) 'bare' option user/berick/lp1824391-print-to-file-with-jdk11
authorBill Erickson <berickxx@gmail.com>
Fri, 12 Apr 2019 19:23:38 +0000 (15:23 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 12 Apr 2019 20:08:34 +0000 (16:08 -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 400e02c..e178951 100644 (file)
@@ -145,8 +145,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);