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

(-)a/src/components/src/main/java/org/apache/jmeter/extractor/json/jsonpath/JSONManager.java (-1 / +1 lines)
Lines 95-101 public class JSONManager { Link Here
95
        if (obj instanceof JSONArray) {
95
        if (obj instanceof JSONArray) {
96
            return ((JSONArray)obj).toJSONString();
96
            return ((JSONArray)obj).toJSONString();
97
        }
97
        }
98
        return obj == null ? "" : obj.toString(); //$NON-NLS-1$
98
        return obj == null ? null : obj.toString();
99
    }
99
    }
100
100
101
}
101
}
(-)a/src/components/src/main/java/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java (-11 / +14 lines)
Lines 123-129 public class JSONPostProcessor Link Here
123
            handleListResult(vars, defaultValues, i, matchNumber, currentRefName, extractedValues);
123
            handleListResult(vars, defaultValues, i, matchNumber, currentRefName, extractedValues);
124
        } else {
124
        } else {
125
            // else just one value extracted
125
            // else just one value extracted
126
            handleSingleResult(vars, matchNumber, currentRefName, extractedValues);
126
            handleSingleResult(vars, defaultValues, matchNumber, currentRefName, extractedValues);
127
        }
127
        }
128
        if (matchNumber != 0) {
128
        if (matchNumber != 0) {
129
            vars.put(currentRefName + REF_MATCH_NR, Integer.toString(extractedValues.size()));
129
            vars.put(currentRefName + REF_MATCH_NR, Integer.toString(extractedValues.size()));
Lines 142-151 public class JSONPostProcessor Link Here
142
        }
142
        }
143
    }
143
    }
144
144
145
    private void handleSingleResult(JMeterVariables vars, final int matchNumber, String currentRefName,
145
    private void handleSingleResult(JMeterVariables vars, String[] defaultValues, final int matchNumber,
146
            List<Object> extractedValues) {
146
            String currentRefName, List<Object> extractedValues) {
147
        String suffix = (matchNumber < 0) ? "_1" : "";
147
        String suffix = (matchNumber < 0) ? "_1" : "";
148
        placeObjectIntoVars(vars, currentRefName + suffix, extractedValues, 0);
148
        String defaultValue = defaultValues.length > 0 ? defaultValues[0] : "";
149
        placeObjectIntoVars(vars, currentRefName + suffix, extractedValues, 0, defaultValue);
149
        if (matchNumber < 0 && getComputeConcatenation()) {
150
        if (matchNumber < 0 && getComputeConcatenation()) {
150
            vars.put(currentRefName + ALL_SUFFIX, vars.get(currentRefName + suffix));
151
            vars.put(currentRefName + ALL_SUFFIX, vars.get(currentRefName + suffix));
151
        }
152
        }
Lines 161-167 public class JSONPostProcessor Link Here
161
                            ? extractedValues.size() * 20
162
                            ? extractedValues.size() * 20
162
                            : 1);
163
                            : 1);
163
            for (Object extractedObject : extractedValues) {
164
            for (Object extractedObject : extractedValues) {
164
                String extractedString = stringify(extractedObject);
165
                String defaultValue = defaultValues.length > i ? defaultValues[i] : "";
166
                String extractedString = StringUtils.defaultString(stringify(extractedObject), defaultValue);
165
                vars.put(currentRefName + "_" + index,
167
                vars.put(currentRefName + "_" + index,
166
                        extractedString); //$NON-NLS-1$
168
                        extractedString); //$NON-NLS-1$
167
                if (getComputeConcatenation()) {
169
                if (getComputeConcatenation()) {
Lines 180-187 public class JSONPostProcessor Link Here
180
            // Random extraction
182
            // Random extraction
181
            int matchSize = extractedValues.size();
183
            int matchSize = extractedValues.size();
182
            int matchNr = JMeterUtils.getRandomInt(matchSize);
184
            int matchNr = JMeterUtils.getRandomInt(matchSize);
185
            String defaultValue = defaultValues.length > 0 ? defaultValues[0] : "";
183
            placeObjectIntoVars(vars, currentRefName,
186
            placeObjectIntoVars(vars, currentRefName,
184
                    extractedValues, matchNr);
187
                    extractedValues, matchNr, defaultValue);
185
            return;
188
            return;
186
        }
189
        }
187
        // extract at position
190
        // extract at position
Lines 193-199 public class JSONPostProcessor Link Here
193
            }
196
            }
194
            vars.put(currentRefName, defaultValues[i]);
197
            vars.put(currentRefName, defaultValues[i]);
195
        } else {
198
        } else {
196
            placeObjectIntoVars(vars, currentRefName, extractedValues, matchNumber - 1);
199
            String defaultValue = defaultValues.length > 0 ? defaultValues[0] : "";
200
            placeObjectIntoVars(vars, currentRefName, extractedValues, matchNumber - 1, defaultValue);
197
        }
201
        }
198
    }
202
    }
199
203
Lines 245-257 public class JSONPostProcessor Link Here
245
    }
249
    }
246
250
247
    private void placeObjectIntoVars(JMeterVariables vars, String currentRefName,
251
    private void placeObjectIntoVars(JMeterVariables vars, String currentRefName,
248
            List<Object> extractedValues, int matchNr) {
252
            List<Object> extractedValues, int matchNr, String defaultValue) {
249
        vars.put(currentRefName,
253
        vars.put(currentRefName,
250
                stringify(extractedValues.get(matchNr)));
254
                StringUtils.defaultString(stringify(extractedValues.get(matchNr)), defaultValue));
251
    }
255
    }
252
256
253
    private String stringify(Object obj) {
257
    private String stringify(Object obj) {
254
        return obj == null ? "" : obj.toString(); //$NON-NLS-1$
258
        return obj == null ? null : obj.toString();
255
    }
259
    }
256
260
257
    public String getJsonPathExpressions() {
261
    public String getJsonPathExpressions() {
258
- 

Return to bug 65681