Skip to content

Commit a5081e5

Browse files
authored
refactor: use JSONArray.fromObject replace jsonSlurper.parseText (#1075)
1 parent 2b6ab4a commit a5081e5

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

src/main/java/jenkins/plugins/slack/workflow/SlackSendStep.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
import jenkins.plugins.slack.StandardSlackService;
2424
import jenkins.plugins.slack.StandardSlackServiceBuilder;
2525
import jenkins.plugins.slack.user.SlackUserIdResolver;
26-
import net.sf.json.JSON;
2726
import net.sf.json.JSONArray;
2827
import net.sf.json.JSONException;
2928
import net.sf.json.JSONObject;
30-
import net.sf.json.groovy.JsonSlurper;
3129
import org.jenkinsci.plugins.workflow.steps.Step;
3230
import org.jenkinsci.plugins.workflow.steps.StepContext;
3331
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
@@ -408,19 +406,12 @@ JSONArray getBlocksAsJSONArray() throws Exception {
408406
}
409407

410408
private JSONArray convertStringToJsonArray(TaskListener listener, String jsonString, String fieldType) {
411-
JsonSlurper jsonSlurper = new JsonSlurper();
412-
JSON json;
413409
try {
414-
json = jsonSlurper.parseText(jsonString);
410+
return JSONArray.fromObject(jsonString);
415411
} catch (JSONException e) {
416412
listener.error(Messages.notificationFailedWithException(e));
417413
return null;
418414
}
419-
if (!(json instanceof JSONArray)) {
420-
listener.error(Messages.notificationFailedWithException(new IllegalArgumentException(fieldType + " must be JSONArray")));
421-
return null;
422-
}
423-
return (JSONArray) json;
424415
}
425416

426417
JSONArray getAttachmentsAsJSONArray() throws Exception {

0 commit comments

Comments
 (0)