static JSONObject parametersToJsonObject(Map<String, String> params) throws JSONException { JSONObject root = new JSONObject(); for (Map.Entry<String, String> entry : params.entrySet()) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(root, path, 0); if (path.length > 1) { holder.put(path[path.length - 1], convertToJsonValue(entry.getValue())); } else { holder.put(path[0], convertToJsonValue(entry.getValue())); } } return root; }
static JSONObject parametersToJsonObject(Map<String, String> params) throws JSONException { JSONObject root = new JSONObject(); for (Map.Entry<String, String> entry : params.entrySet()) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(root, path, 0); if (path.length > 1) { holder.put(path[path.length - 1], convertToJsonValue(entry.getValue())); } else { holder.put(path[0], convertToJsonValue(entry.getValue())); } } return root; }
static JSONObject parametersToJsonObject(Map<String, String> params) throws JSONException { JSONObject root = new JSONObject(); for (Map.Entry<String, String> entry : params.entrySet()) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(root, path, 0); if (path.length > 1) { holder.put(path[path.length - 1], convertToJsonValue(entry.getValue())); } else { holder.put(path[0], convertToJsonValue(entry.getValue())); } } return root; }
static JSONObject parametersToJsonObject(Map<String, String> params) throws JSONException { JSONObject root = new JSONObject(); for (Map.Entry<String, String> entry : params.entrySet()) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(root, path, 0); if (path.length > 1) { holder.put(path[path.length - 1], convertToJsonValue(entry.getValue())); } else { holder.put(path[0], convertToJsonValue(entry.getValue())); } } return root; }
static JSONObject parametersToJsonObject(Map<String, String> params) throws JSONException { JSONObject root = new JSONObject(); for (Map.Entry<String, String> entry : params.entrySet()) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(root, path, 0); if (path.length > 1) { holder.put(path[path.length - 1], convertToJsonValue(entry.getValue())); } else { holder.put(path[0], convertToJsonValue(entry.getValue())); } } return root; }
@SuppressWarnings("unchecked") public static JSONObject fromRequest(HttpServletRequest request) throws JSONException { Map<String, String[]> params = request.getParameterMap(); if (!params.containsKey("method")) { return null; } JSONObject root = new JSONObject(); root.put("method", params.get("method")[0]); if (params.containsKey("id")) { root.put("id", params.get("id")[0]); } JSONObject paramsRoot = new JSONObject(); for (Map.Entry<String, String[]> entry : params.entrySet()) { if (!RESERVED_PARAMS.contains(entry.getKey().toLowerCase())) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(paramsRoot, path, 0); holder.put(path[path.length - 1], convertToJsonValue(entry.getValue()[0])); } } if (paramsRoot.length() > 0) { root.put("params", paramsRoot); } return root; }
@SuppressWarnings("unchecked") public static JSONObject fromRequest(HttpServletRequest request) throws JSONException { Map<String, String[]> params = request.getParameterMap(); if (!params.containsKey("method")) { return null; } JSONObject root = new JSONObject(); root.put("method", params.get("method")[0]); if (params.containsKey("id")) { root.put("id", params.get("id")[0]); } JSONObject paramsRoot = new JSONObject(); for (Map.Entry<String, String[]> entry : params.entrySet()) { if (!RESERVED_PARAMS.contains(entry.getKey().toLowerCase())) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(paramsRoot, path, 0); holder.put(path[path.length - 1], convertToJsonValue(entry.getValue()[0])); } } if (paramsRoot.length() > 0) { root.put("params", paramsRoot); } return root; }
@SuppressWarnings("unchecked") public static JSONObject fromRequest(HttpServletRequest request) throws JSONException { Map<String, String[]> params = request.getParameterMap(); if (!params.containsKey("method")) { return null; } JSONObject root = new JSONObject(); root.put("method", params.get("method")[0]); if (params.containsKey("id")) { root.put("id", params.get("id")[0]); } JSONObject paramsRoot = new JSONObject(); for (Map.Entry<String, String[]> entry : params.entrySet()) { if (!RESERVED_PARAMS.contains(entry.getKey().toLowerCase())) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(paramsRoot, path, 0); holder.put(path[path.length - 1], convertToJsonValue(entry.getValue()[0])); } } if (paramsRoot.length() > 0) { root.put("params", paramsRoot); } return root; }
@SuppressWarnings("unchecked") public static JSONObject fromRequest(HttpServletRequest request) throws JSONException { Map<String, String[]> params = request.getParameterMap(); if (!params.containsKey("method")) { return null; } JSONObject root = new JSONObject(); root.put("method", params.get("method")[0]); if (params.containsKey("id")) { root.put("id", params.get("id")[0]); } JSONObject paramsRoot = new JSONObject(); for (Map.Entry<String, String[]> entry : params.entrySet()) { if (!RESERVED_PARAMS.contains(entry.getKey().toLowerCase())) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(paramsRoot, path, 0); holder.put(path[path.length - 1], convertToJsonValue(entry.getValue()[0])); } } if (paramsRoot.length() > 0) { root.put("params", paramsRoot); } return root; }
@SuppressWarnings("unchecked") public static JSONObject fromRequest(HttpServletRequest request) throws JSONException { Map<String, String[]> params = request.getParameterMap(); if (!params.containsKey("method")) { return null; } JSONObject root = new JSONObject(); root.put("method", params.get("method")[0]); if (params.containsKey("id")) { root.put("id", params.get("id")[0]); } JSONObject paramsRoot = new JSONObject(); for (Map.Entry<String, String[]> entry : params.entrySet()) { if (!RESERVED_PARAMS.contains(entry.getKey().toLowerCase())) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(paramsRoot, path, 0); holder.put(path[path.length - 1], convertToJsonValue(entry.getValue()[0])); } } if (paramsRoot.length() > 0) { root.put("params", paramsRoot); } return root; }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }
@Test public void testArrayPathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a(0).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(1).a".split("\\."), 0); JsonConversionUtil.buildHolder(root, "a.a(2).a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}")); }
@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }
@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }
@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }
@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }
@Test public void testSimplePathToJsonParsing() throws Exception { JSONObject root = new JSONObject(); JsonConversionUtil.buildHolder(root, "a.a.a".split("\\."), 0); assertJsonEquals(root, new JSONObject("{a:{a:{}}}")); }