You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2018/11/07 17:19:24 UTC
svn commit: r1846060 - in /jmeter/trunk:
src/components/org/apache/jmeter/visualizers/RenderAsJSON.java
test/src/org/apache/jmeter/visualizers/TestRenderAsJson.java
xdocs/changes.xml
Author: fschumacher
Date: Wed Nov 7 17:19:24 2018
New Revision: 1846060
URL: http://svn.apache.org/viewvc?rev=1846060&view=rev
Log:
Format JSON Arrays when displayed with JSON Path Tester
Bugzilla Id: 62889
Modified:
jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java
jmeter/trunk/test/src/org/apache/jmeter/visualizers/TestRenderAsJson.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java?rev=1846060&r1=1846059&r2=1846060&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java Wed Nov 7 17:19:24 2018
@@ -25,8 +25,10 @@ import org.apache.commons.lang3.StringUt
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;
+import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.JSONStyle;
+import net.minidev.json.JSONValue;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
@@ -57,7 +59,7 @@ public class RenderAsJSON extends Sample
public static String prettyJSON(String json) {
return prettyJSON(json, TAB_SEPARATOR);
}
-
+
/**
* Pretty-print JSON text
* @param json input text
@@ -71,6 +73,12 @@ public class RenderAsJSON extends Sample
if (o instanceof JSONObject) {
return ((JSONObject) o)
.toJSONString(new PrettyJSONStyle(tabSeparator));
+ } else if (o instanceof JSONArray) {
+ return ((JSONArray) o)
+ .toJSONString(new PrettyJSONStyle(tabSeparator));
+ } else if (o instanceof JSONValue) {
+ return ((JSONValue) o)
+ .toJSONString(new PrettyJSONStyle(tabSeparator));
}
} catch (ParseException e) {
return json;
Modified: jmeter/trunk/test/src/org/apache/jmeter/visualizers/TestRenderAsJson.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/visualizers/TestRenderAsJson.java?rev=1846060&r1=1846059&r2=1846060&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/visualizers/TestRenderAsJson.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/visualizers/TestRenderAsJson.java Wed Nov 7 17:19:24 2018
@@ -60,8 +60,12 @@ public class TestRenderAsJson {
}
@Test
+ public void testRenderResultComplexArray() throws Exception {
+ assertEquals("[\n" + TAB + "1,\n" + TAB + "{\n" + TAB + TAB + "\"A\": \"B\"\n" + TAB + "}\n]", prettyJSON("[1,{\"A\":\"B\"}]"));
+ }
+ @Test
public void testRenderResultSimpleArray() throws Exception {
- assertEquals("[]", prettyJSON("[]"));
+ assertEquals("[\n]", prettyJSON("[]"));
}
@Test
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1846060&r1=1846059&r2=1846060&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Wed Nov 7 17:19:24 2018
@@ -195,6 +195,7 @@ of previous time slot as a base. Startin
<li><bug>62790</bug><code>ArrayIndexOutOfBoundsException</code> when calling replace without selecting the first match</li>
<li><bug>62795</bug>JMeter master sometimes ends distributed test even though some of the slaves have not finished</li>
<li><bug>62336</bug><pr>396</pr>Some shortcuts are not working correctly on windows. Contributed by Michael Pavlov (michael.paulau at gmail.com)</li>
+ <li><bug>62889</bug>Format JSON Arrays when displayed with JSON Path Tester.</li>
</ul>
<!-- =================== Thanks =================== -->