View | Details | Raw Unified | Return to bug 62889
Collapse All | Expand All

(-)a/src/components/org/apache/jmeter/visualizers/RenderAsJSON.java (-1 / +9 lines)
Lines 25-32 import org.apache.commons.lang3.StringUtils; Link Here
25
import org.apache.jmeter.samplers.SampleResult;
25
import org.apache.jmeter.samplers.SampleResult;
26
import org.apache.jmeter.util.JMeterUtils;
26
import org.apache.jmeter.util.JMeterUtils;
27
27
28
import net.minidev.json.JSONArray;
28
import net.minidev.json.JSONObject;
29
import net.minidev.json.JSONObject;
29
import net.minidev.json.JSONStyle;
30
import net.minidev.json.JSONStyle;
31
import net.minidev.json.JSONValue;
30
import net.minidev.json.parser.JSONParser;
32
import net.minidev.json.parser.JSONParser;
31
import net.minidev.json.parser.ParseException;
33
import net.minidev.json.parser.ParseException;
32
34
Lines 57-63 public class RenderAsJSON extends SamplerResultTab implements ResultRenderer { Link Here
57
    public static String prettyJSON(String json) {
59
    public static String prettyJSON(String json) {
58
        return prettyJSON(json, TAB_SEPARATOR);
60
        return prettyJSON(json, TAB_SEPARATOR);
59
    }
61
    }
60
    
62
61
    /**
63
    /**
62
     * Pretty-print JSON text
64
     * Pretty-print JSON text
63
     * @param json input text
65
     * @param json input text
Lines 71-76 public class RenderAsJSON extends SamplerResultTab implements ResultRenderer { Link Here
71
            if (o instanceof JSONObject) {
73
            if (o instanceof JSONObject) {
72
                return ((JSONObject) o)
74
                return ((JSONObject) o)
73
                        .toJSONString(new PrettyJSONStyle(tabSeparator));
75
                        .toJSONString(new PrettyJSONStyle(tabSeparator));
76
            } else if (o instanceof JSONArray) {
77
                return ((JSONArray) o)
78
                        .toJSONString(new PrettyJSONStyle(tabSeparator));
79
            } else if (o instanceof JSONValue) {
80
                return ((JSONValue) o)
81
                        .toJSONString(new PrettyJSONStyle(tabSeparator));
74
            }
82
            }
75
        } catch (ParseException e) {
83
        } catch (ParseException e) {
76
            return json;
84
            return json;
(-)a/test/src/org/apache/jmeter/visualizers/TestRenderAsJson.java (-1 / +5 lines)
Lines 59-67 public class TestRenderAsJson { Link Here
59
        assertEquals("{\n}", prettyJSON("{}"));
59
        assertEquals("{\n}", prettyJSON("{}"));
60
    }
60
    }
61
61
62
    @Test
63
    public void testRenderResultComplexArray() throws Exception {
64
        assertEquals("[\n" + TAB + "1,\n" + TAB + "{\n" + TAB + TAB + "\"A\": \"B\"\n" + TAB + "}\n]", prettyJSON("[1,{\"A\":\"B\"}]"));
65
    }
62
    @Test
66
    @Test
63
    public void testRenderResultSimpleArray() throws Exception {
67
    public void testRenderResultSimpleArray() throws Exception {
64
        assertEquals("[]", prettyJSON("[]"));
68
        assertEquals("[\n]", prettyJSON("[]"));
65
    }
69
    }
66
70
67
    @Test
71
    @Test

Return to bug 62889