Skip to content

Commit 733a0ab

Browse files
committed
feat: migrate to Jackson 3.x (tools.jackson 3.2.1) per easy4j-deploy spec
1 parent 09adcde commit 733a0ab

7 files changed

Lines changed: 45 additions & 38 deletions

File tree

‎pom.xml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<!-- Dependency versions -->
6262
<commons-exec.version>1.6.0</commons-exec.version>
6363
<commons-lang.version>2.6</commons-lang.version>
64-
<jackson.version>2.18.9</jackson.version>
64+
<jackson-bom.version>3.2.1</jackson-bom.version>
6565
<junit-jupiter.version>6.1.0</junit-jupiter.version>
6666
<junit.version>4.13.2</junit.version>
6767
<lombok.version>1.18.46</lombok.version>
@@ -107,9 +107,9 @@
107107
</dependency>
108108
<!-- For Jackson BOM -->
109109
<dependency>
110-
<groupId>com.fasterxml.jackson</groupId>
110+
<groupId>tools.jackson</groupId>
111111
<artifactId>jackson-bom</artifactId>
112-
<version>2.21.5</version>
112+
<version>${jackson-bom.version}</version>
113113
<type>pom</type>
114114
<scope>import</scope>
115115
</dependency>
@@ -182,7 +182,7 @@
182182
</dependency>
183183

184184
<dependency>
185-
<groupId>com.fasterxml.jackson.core</groupId>
185+
<groupId>tools.jackson.core</groupId>
186186
<artifactId>jackson-databind</artifactId>
187187
</dependency>
188188

‎src/main/java/io/github/easy4j/opencode/OpenCodeClient.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.easy4j.opencode;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import tools.jackson.databind.ObjectMapper;
4+
import tools.jackson.databind.json.JsonMapper;
45
import io.github.easy4j.opencode.api.mapper.ChatMessageMapper;
56
import io.github.easy4j.opencode.api.model.*;
67
import io.github.easy4j.opencode.cli.OpenCodeCli;
@@ -88,7 +89,7 @@ public class OpenCodeClient implements AutoCloseable {
8889
* @throws IllegalStateException 启用启动检查和快速失败后,对应子系统不可用
8990
*/
9091
public OpenCodeClient(OpenCodeHttpClientConfig httpConfig) {
91-
this(httpConfig, new OpenCodeCliConfig(), new ObjectMapper(), null);
92+
this(httpConfig, new OpenCodeCliConfig(), new JsonMapper(), null);
9293
}
9394

9495
/**
@@ -110,7 +111,7 @@ public OpenCodeClient(OpenCodeHttpClientConfig httpConfig, ObjectMapper objectMa
110111
* @throws IllegalStateException 启用启动检查和快速失败后,对应子系统不可用
111112
*/
112113
public OpenCodeClient(OpenCodeCliConfig cliConfig) {
113-
this(new OpenCodeHttpClientConfig(), cliConfig, new ObjectMapper(), null);
114+
this(new OpenCodeHttpClientConfig(), cliConfig, new JsonMapper(), null);
114115
}
115116

116117
/**
@@ -133,7 +134,7 @@ public OpenCodeClient(OpenCodeCliConfig cliConfig, ObjectMapper objectMapper, Ok
133134
* @throws IllegalStateException 启用启动检查和快速失败后,对应子系统不可用
134135
*/
135136
public OpenCodeClient(OpenCodeHttpClientConfig httpConfig, OpenCodeCliConfig cliConfig) {
136-
this(httpConfig, cliConfig, new ObjectMapper(), null);
137+
this(httpConfig, cliConfig, new JsonMapper(), null);
137138
}
138139

139140
/**
@@ -199,7 +200,7 @@ public OpenCodeClient(OpenCodeHttpClientConfig httpConfig, OpenCodeCliConfig cli
199200
* @throws IllegalStateException 启用启动检查和快速失败后,对应子系统不可用
200201
*/
201202
public OpenCodeClient(OpenCodeClientConfig config) {
202-
this(config, new ObjectMapper(), null);
203+
this(config, new JsonMapper(), null);
203204
}
204205

205206
/**

‎src/main/java/io/github/easy4j/opencode/api/OpenCodeChatClient.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.easy4j.opencode.api;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import tools.jackson.databind.ObjectMapper;
4+
import tools.jackson.databind.json.JsonMapper;
45
import io.github.easy4j.opencode.HttpCallCancellation;
56
import io.github.easy4j.opencode.OpenCodeHttpClientConfig;
67
import io.github.easy4j.opencode.api.mapper.ChatMessageMapper;
@@ -56,7 +57,7 @@ public class OpenCodeChatClient extends OpenCodeHttpClient {
5657
* @param config 客户端配置;不得为 {@code null}
5758
*/
5859
public OpenCodeChatClient(OpenCodeHttpClientConfig config) {
59-
this(config, new ObjectMapper(), null);
60+
this(config, new JsonMapper(), null);
6061
}
6162

6263
/**

‎src/main/java/io/github/easy4j/opencode/api/OpenCodeHttpClient.java‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package io.github.easy4j.opencode.api;
22

3-
import com.fasterxml.jackson.core.type.TypeReference;
4-
import com.fasterxml.jackson.databind.DeserializationFeature;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import tools.jackson.core.JacksonException;
4+
import tools.jackson.core.type.TypeReference;
5+
import tools.jackson.databind.DeserializationFeature;
6+
import tools.jackson.databind.ObjectMapper;
7+
import tools.jackson.databind.json.JsonMapper;
68
import io.github.easy4j.opencode.OpenCodeHttpClientConfig;
79
import io.github.easy4j.opencode.HttpCallCancellation;
810
import io.github.easy4j.opencode.OpenCodeOkHttpClientFactory;
@@ -76,8 +78,8 @@ public class OpenCodeHttpClient implements AutoCloseable {
7678
*/
7779
public OpenCodeHttpClient(OpenCodeHttpClientConfig config, ObjectMapper objectMapper, OkHttpClient httpClient) {
7880
this.config = Objects.requireNonNull(config, "config");
79-
this.objectMapper = Objects.isNull(objectMapper) ? new ObjectMapper()
80-
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false): objectMapper;
81+
this.objectMapper = Objects.isNull(objectMapper) ? JsonMapper.builder()
82+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build(): objectMapper;
8183
this.httpClient = Objects.isNull(httpClient) ? buildOkHttpClient(config) : httpClient;
8284
if (allows(HttpLogLevel.BASIC)) {
8385
log.debug("OpenCode HTTP client initialized: baseUrl={}, connectTimeoutMs={}, readTimeoutMs={}, "
@@ -485,7 +487,7 @@ public CompletableFuture<Boolean> promptAsync(String sessionId, PromptRequest re
485487
Request httpReq = authedRequest(url("/session/" + sessionId + "/prompt_async"), context)
486488
.post(body).build();
487489
return executeSuccessAsync(httpReq, null);
488-
} catch (IOException e) {
490+
} catch (JacksonException e) {
489491
return failedFuture(new OpenCodeHttpException("promptAsync failed: " + e.getMessage(), e));
490492
}
491493
}
@@ -1397,7 +1399,7 @@ protected <T> CompletableFuture<T> executeAsync(Request request, Class<T> type,
13971399
}
13981400
try {
13991401
return objectMapper.readValue(response.getBody(), type);
1400-
} catch (IOException error) {
1402+
} catch (JacksonException error) {
14011403
throw new OpenCodeHttpException("Failed to parse response: " + error.getMessage(), error);
14021404
}
14031405
});
@@ -1476,7 +1478,7 @@ private <T> CompletableFuture<T> executeListAsync(Request request, TypeReference
14761478
}
14771479
try {
14781480
return objectMapper.readValue(response.getBody(), typeRef);
1479-
} catch (IOException error) {
1481+
} catch (JacksonException error) {
14801482
throw new OpenCodeHttpException("Failed to parse response: " + error.getMessage(), error);
14811483
}
14821484
});
@@ -1618,7 +1620,7 @@ private Headers redactHeaders(Headers headers) {
16181620
private String toJson(Object body) {
16191621
try {
16201622
return objectMapper.writeValueAsString(body);
1621-
} catch (IOException e) {
1623+
} catch (JacksonException e) {
16221624
throw new OpenCodeHttpException("Failed to serialize request body: " + e.getMessage(), e);
16231625
}
16241626
}

‎src/main/java/io/github/easy4j/opencode/api/OpenCodeSseClient.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package io.github.easy4j.opencode.api;
22

3-
import com.fasterxml.jackson.databind.DeserializationFeature;
4-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import tools.jackson.databind.DeserializationFeature;
4+
import tools.jackson.databind.ObjectMapper;
5+
import tools.jackson.databind.json.JsonMapper;
56
import io.github.easy4j.opencode.OpenCodeHttpClientConfig;
67
import io.github.easy4j.opencode.OpenCodeOkHttpClientFactory;
78
import io.github.easy4j.opencode.api.event.EventHandler;
@@ -63,7 +64,7 @@ public class OpenCodeSseClient implements AutoCloseable {
6364
* @param config 客户端配置;不得为 {@code null}
6465
*/
6566
public OpenCodeSseClient(OpenCodeHttpClientConfig config) {
66-
this(config, new ObjectMapper(), null);
67+
this(config, new JsonMapper(), null);
6768
}
6869

6970
/**
@@ -76,8 +77,8 @@ public OpenCodeSseClient(OpenCodeHttpClientConfig config) {
7677
public OpenCodeSseClient(OpenCodeHttpClientConfig config, ObjectMapper objectMapper,
7778
OkHttpClient httpClient) {
7879
this.config = Objects.requireNonNull(config, "config");
79-
this.mapper = Objects.isNull(objectMapper) ? new ObjectMapper()
80-
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) : objectMapper;
80+
this.mapper = Objects.isNull(objectMapper) ? JsonMapper.builder()
81+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build() : objectMapper;
8182
this.ownsHttpClient = Objects.isNull(httpClient);
8283
OkHttpClient baseClient = ownsHttpClient
8384
? OpenCodeOkHttpClientFactory.create(config) : httpClient;

‎src/main/java/io/github/easy4j/opencode/api/mapper/OpenCodeCallbackParser.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package io.github.easy4j.opencode.api.mapper;
22

3-
import com.fasterxml.jackson.core.type.TypeReference;
4-
import com.fasterxml.jackson.databind.DeserializationFeature;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import tools.jackson.core.type.TypeReference;
4+
import tools.jackson.databind.DeserializationFeature;
5+
import tools.jackson.databind.ObjectMapper;
6+
import tools.jackson.databind.json.JsonMapper;
67
import io.github.easy4j.opencode.api.model.PromptResult;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
@@ -37,8 +38,8 @@ public class OpenCodeCallbackParser {
3738
/**
3839
* 用于解析回调 JSON 的共享映射器,允许注释并忽略服务端新增字段。
3940
*/
40-
private static final ObjectMapper MAPPER = new ObjectMapper()
41-
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
41+
private static final ObjectMapper MAPPER = JsonMapper.builder()
42+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build();
4243

4344
/**
4445
* 匹配 ```json ... ``` 代码块中的 JSON。

‎src/test/java/io/github/easy4j/opencode/OpenCodeClientTest.java‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.easy4j.opencode;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import tools.jackson.databind.ObjectMapper;
4+
import tools.jackson.databind.json.JsonMapper;
45
import io.github.easy4j.opencode.api.OpenCodeHttpClient;
56
import io.github.easy4j.opencode.api.OpenCodeSseClient;
67
import io.github.easy4j.opencode.cli.OpenCodeCli;
@@ -42,7 +43,7 @@ void shouldCreateClientWithHttpConfigOnly() {
4243
OpenCodeHttpClientConfig httpConfig = new OpenCodeHttpClientConfig();
4344
httpConfig.setBaseUrl(server.url("/").toString().replaceAll("/$", ""));
4445
OpenCodeClientConfig config = new OpenCodeClientConfig();
45-
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new ObjectMapper(), null);
46+
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new JsonMapper(), null);
4647
OpenCodeClient client = new OpenCodeClient(config, httpClient, null, null);
4748

4849
assertTrue(client.isHttpEnabled());
@@ -68,7 +69,7 @@ void shouldCreateClientWithBothSubsystems() {
6869
OpenCodeHttpClientConfig httpConfig = new OpenCodeHttpClientConfig();
6970
httpConfig.setBaseUrl(server.url("/").toString().replaceAll("/$", ""));
7071
OpenCodeClientConfig config = new OpenCodeClientConfig();
71-
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new ObjectMapper(), null);
72+
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new JsonMapper(), null);
7273
OpenCodeCliExecutor executor = new OpenCodeCliExecutor(config.getCli());
7374
OpenCodeCli cli = new OpenCodeCli(executor);
7475
OpenCodeClient client = new OpenCodeClient(config, httpClient, null, cli);
@@ -128,7 +129,7 @@ void shouldDelegateHealthToHttpClient() {
128129
.setBody("{\"healthy\":true,\"version\":\"1.0.0\"}"));
129130

130131
OpenCodeClientConfig config = new OpenCodeClientConfig();
131-
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new ObjectMapper(), null);
132+
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new JsonMapper(), null);
132133
OpenCodeClient client = new OpenCodeClient(config, httpClient, null, null);
133134

134135
var health = client.health();
@@ -146,7 +147,7 @@ void shouldDelegateListSessions() {
146147
.setBody("[{\"id\":\"sess-1\",\"title\":\"test\"}]"));
147148

148149
OpenCodeClientConfig config = new OpenCodeClientConfig();
149-
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new ObjectMapper(), null);
150+
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new JsonMapper(), null);
150151
OpenCodeClient client = new OpenCodeClient(config, httpClient, null, null);
151152

152153
var sessions = client.listSessions();
@@ -164,7 +165,7 @@ void shouldDelegateListAgents() {
164165
.setBody("[{\"name\":\"coder\"}]"));
165166

166167
OpenCodeClientConfig config = new OpenCodeClientConfig();
167-
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new ObjectMapper(), null);
168+
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new JsonMapper(), null);
168169
OpenCodeClient client = new OpenCodeClient(config, httpClient, null, null);
169170

170171
var agents = client.listAgents();
@@ -182,7 +183,7 @@ void shouldDelegateGetConfig() {
182183
.setBody("{\"theme\":\"dark\"}"));
183184

184185
OpenCodeClientConfig config = new OpenCodeClientConfig();
185-
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new ObjectMapper(), null);
186+
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new JsonMapper(), null);
186187
OpenCodeClient client = new OpenCodeClient(config, httpClient, null, null);
187188

188189
var codeConfig = client.getOpenCodeConfig();
@@ -200,7 +201,7 @@ void shouldDelegateAbort() {
200201
.setBody("{}"));
201202

202203
OpenCodeClientConfig config = new OpenCodeClientConfig();
203-
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new ObjectMapper(), null);
204+
OpenCodeHttpClient httpClient = new OpenCodeHttpClient(httpConfig, new JsonMapper(), null);
204205
OpenCodeClient client = new OpenCodeClient(config, httpClient, null, null);
205206

206207
assertTrue(client.abort("sess-1"));

0 commit comments

Comments
 (0)