Skip to content

Commit 33fba12

Browse files
committed
Upgrade to Spring AI 2.0.0
1 parent e6d7d3c commit 33fba12

9 files changed

Lines changed: 45 additions & 45 deletions

File tree

‎core/src/main/java/com/javaaidev/agenticpatterns/core/AgentUtils.java‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.javaaidev.agenticpatterns.core;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
4-
import com.fasterxml.jackson.core.type.TypeReference;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
6-
import com.fasterxml.jackson.databind.SerializationFeature;
73
import java.io.IOException;
84
import java.nio.charset.StandardCharsets;
95
import java.util.HashMap;
@@ -12,11 +8,17 @@
128
import java.util.function.Function;
139
import org.jspecify.annotations.Nullable;
1410
import org.springframework.core.io.ClassPathResource;
11+
import tools.jackson.core.JacksonException;
12+
import tools.jackson.core.type.TypeReference;
13+
import tools.jackson.databind.ObjectMapper;
14+
import tools.jackson.databind.SerializationFeature;
15+
import tools.jackson.databind.json.JsonMapper;
1516

1617
public class AgentUtils {
1718

18-
private static final ObjectMapper objectMapper = new ObjectMapper().enable(
19-
SerializationFeature.INDENT_OUTPUT);
19+
private static final ObjectMapper objectMapper = JsonMapper.builder()
20+
.enable(SerializationFeature.INDENT_OUTPUT)
21+
.build();
2022

2123
/**
2224
* Load prompt template from classpath by name
@@ -68,7 +70,7 @@ public static String toJson(@Nullable Object input) {
6870
}
6971
try {
7072
return objectMapper.writeValueAsString(input);
71-
} catch (JsonProcessingException e) {
73+
} catch (JacksonException e) {
7274
return "{}";
7375
}
7476
}
@@ -87,7 +89,7 @@ public static Map<String, Object> objectToMap(@Nullable Object object) {
8789
try {
8890
return objectMapper.readValue(json, new TypeReference<>() {
8991
});
90-
} catch (JsonProcessingException e) {
92+
} catch (JacksonException e) {
9193
return new HashMap<>();
9294
}
9395
}

‎examples/pom.xml‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<maven.compiler.source>21</maven.compiler.source>
1919
<maven.compiler.target>21</maven.compiler.target>
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<spring-ai.version>1.1.1</spring-ai.version>
22-
<spring-boot.version>3.5.9</spring-boot.version>
21+
<spring-ai.version>2.0.0-M7</spring-ai.version>
22+
<spring-boot.version>4.0.6</spring-boot.version>
2323
</properties>
2424

2525
<dependencyManagement>
@@ -41,7 +41,7 @@
4141
<dependency>
4242
<groupId>io.opentelemetry.instrumentation</groupId>
4343
<artifactId>opentelemetry-instrumentation-bom</artifactId>
44-
<version>2.15.0</version>
44+
<version>2.28.1</version>
4545
<type>pom</type>
4646
<scope>import</scope>
4747
</dependency>
@@ -90,15 +90,18 @@
9090
<groupId>org.springframework.boot</groupId>
9191
<artifactId>spring-boot-starter-actuator</artifactId>
9292
</dependency>
93+
<dependency>
94+
<groupId>org.springframework.ai</groupId>
95+
<artifactId>spring-ai-starter-mcp-client</artifactId>
96+
</dependency>
9397
<dependency>
9498
<groupId>org.springdoc</groupId>
9599
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
96-
<version>2.8.9</version>
100+
<version>3.0.3</version>
97101
</dependency>
98102
<dependency>
99103
<groupId>io.micrometer</groupId>
100104
<artifactId>micrometer-registry-otlp</artifactId>
101-
<version>1.15.5</version>
102105
</dependency>
103106
<dependency>
104107
<groupId>io.micrometer</groupId>

‎patterns/chain-workflow/src/main/java/com/javaaidev/agenticpatterns/chainworkflow/ChainStepAgent.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.javaaidev.agenticpatterns.chainworkflow;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
43
import com.javaaidev.agenticpatterns.core.McpClientConfiguration;
54
import com.javaaidev.agenticpatterns.taskexecution.AbstractTaskExecutionAgentBuilder;
65
import com.javaaidev.agenticpatterns.taskexecution.TaskExecutionAgent;
@@ -14,6 +13,7 @@
1413
import org.springframework.ai.chat.client.ChatClient;
1514
import org.springframework.ai.chat.client.ChatClient.ChatClientRequestSpec;
1615
import org.springframework.util.Assert;
16+
import tools.jackson.databind.json.JsonMapper;
1717

1818
/**
1919
* A step in the chain implemented as a {@linkplain TaskExecutionAgent}
@@ -44,11 +44,11 @@ public ChainStepAgent(ChatClient chatClient,
4444
@Nullable Predicate<String> toolFilter,
4545
@Nullable String name,
4646
@Nullable ObservationRegistry observationRegistry,
47-
@Nullable ObjectMapper objectMapper) {
47+
@Nullable JsonMapper jsonMapper) {
4848
super(chatClient, promptTemplate, responseType,
4949
promptTemplateContextProvider,
5050
chatClientRequestSpecUpdater, mcpClientConfiguration, toolFilter,
51-
name, observationRegistry, objectMapper);
51+
name, observationRegistry, jsonMapper);
5252
}
5353

5454
public static <Req, Res> Builder<Req, Res> builder() {
@@ -86,7 +86,7 @@ public ChainStepAgent<Request, Response> build() {
8686
toolFilter,
8787
name,
8888
observationRegistry,
89-
objectMapper) {
89+
jsonMapper) {
9090
@Override
9191
public Response call(Request request, Map<String, Object> context,
9292
WorkflowChain<Request, Response> chain) {

‎patterns/parallelization-workflow/src/main/java/com/javaaidev/agenticpatterns/parallelizationworkflow/DefaultResponseAssembler.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.javaaidev.agenticpatterns.parallelizationworkflow;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
43
import com.javaaidev.agenticpatterns.core.McpClientConfiguration;
54
import com.javaaidev.agenticpatterns.parallelizationworkflow.DefaultResponseAssembler.AssemblingInput;
65
import com.javaaidev.agenticpatterns.taskexecution.AbstractTaskExecutionAgentBuilder;
@@ -14,6 +13,7 @@
1413
import org.jspecify.annotations.Nullable;
1514
import org.springframework.ai.chat.client.ChatClient;
1615
import org.springframework.ai.chat.client.ChatClient.ChatClientRequestSpec;
16+
import tools.jackson.databind.json.JsonMapper;
1717

1818
/**
1919
* A {@linkplain ResponseAssembler} implemented using {@linkplain TaskExecutionAgent}
@@ -33,11 +33,11 @@ public DefaultResponseAssembler(ChatClient chatClient,
3333
@Nullable Predicate<String> toolFilter,
3434
@Nullable String name,
3535
@Nullable ObservationRegistry observationRegistry,
36-
@Nullable ObjectMapper objectMapper) {
36+
@Nullable JsonMapper jsonMapper) {
3737
super(chatClient, promptTemplate, responseType,
3838
promptTemplateContextProvider,
3939
chatClientRequestSpecUpdater, mcpClientConfiguration, toolFilter,
40-
name, observationRegistry, objectMapper);
40+
name, observationRegistry, jsonMapper);
4141
}
4242

4343
@Override
@@ -68,7 +68,7 @@ public DefaultResponseAssembler<Request, Response> build() {
6868
toolFilter,
6969
name,
7070
observationRegistry,
71-
objectMapper
71+
jsonMapper
7272
);
7373
}
7474
}

‎patterns/task-execution/src/main/java/com/javaaidev/agenticpatterns/taskexecution/AbstractTaskExecutionAgentBuilder.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.javaaidev.agenticpatterns.taskexecution;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
43
import com.javaaidev.agenticpatterns.core.McpClientConfiguration;
54
import io.micrometer.observation.ObservationRegistry;
65
import java.lang.reflect.Type;
@@ -12,6 +11,7 @@
1211
import org.springframework.ai.chat.client.ChatClient;
1312
import org.springframework.ai.chat.client.ChatClient.ChatClientRequestSpec;
1413
import org.springframework.util.Assert;
14+
import tools.jackson.databind.json.JsonMapper;
1515

1616
public abstract class AbstractTaskExecutionAgentBuilder<Request, Response, T extends AbstractTaskExecutionAgentBuilder<Request, Response, T>> implements
1717
TaskExecutionAgent.Builder<Request, Response, T> {
@@ -25,7 +25,7 @@ public abstract class AbstractTaskExecutionAgentBuilder<Request, Response, T ext
2525
protected @Nullable Consumer<ChatClientRequestSpec> chatClientRequestSpecUpdater;
2626
protected @Nullable McpClientConfiguration mcpClientConfiguration;
2727
protected @Nullable Predicate<String> toolFilter;
28-
protected @Nullable ObjectMapper objectMapper;
28+
protected @Nullable JsonMapper jsonMapper;
2929

3030
@SuppressWarnings("unchecked")
3131
protected T self() {
@@ -85,8 +85,8 @@ public T toolFilter(Predicate<String> toolFilter) {
8585
}
8686

8787
@Override
88-
public T objectMapper(ObjectMapper objectMapper) {
89-
this.objectMapper = objectMapper;
88+
public T jsonMapper(JsonMapper jsonMapper) {
89+
this.jsonMapper = jsonMapper;
9090
return self();
9191
}
9292
}

‎patterns/task-execution/src/main/java/com/javaaidev/agenticpatterns/taskexecution/DefaultTaskExecutionAgentBuilder.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public TaskExecutionAgent<Request, Response> build() {
1818
toolFilter,
1919
name,
2020
observationRegistry,
21-
objectMapper) {
21+
jsonMapper) {
2222
};
2323
}
2424
}

‎patterns/task-execution/src/main/java/com/javaaidev/agenticpatterns/taskexecution/TaskExecutionAgent.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.javaaidev.agenticpatterns.taskexecution;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
43
import com.javaaidev.agenticpatterns.core.Agent;
54
import com.javaaidev.agenticpatterns.core.AgentExecutionException;
65
import com.javaaidev.agenticpatterns.core.AgentUtils;
@@ -15,7 +14,7 @@
1514
import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;
1615
import io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport;
1716
import io.modelcontextprotocol.client.transport.StdioClientTransport;
18-
import io.modelcontextprotocol.json.jackson.JacksonMcpJsonMapper;
17+
import io.modelcontextprotocol.json.jackson3.JacksonMcpJsonMapper;
1918
import io.modelcontextprotocol.spec.McpSchema;
2019
import java.lang.reflect.ParameterizedType;
2120
import java.lang.reflect.Type;
@@ -41,6 +40,7 @@
4140
import org.springframework.ai.tool.ToolCallbackProvider;
4241
import org.springframework.core.ParameterizedTypeReference;
4342
import org.springframework.util.CollectionUtils;
43+
import tools.jackson.databind.json.JsonMapper;
4444

4545
/**
4646
* Task Execution Agent, refer to the <a
@@ -63,7 +63,7 @@ public abstract class TaskExecutionAgent<Request, Response> extends
6363
protected McpClientConfiguration mcpClientConfiguration;
6464
protected Predicate<String> toolFilter = (name) -> true;
6565
protected String name = super.getName();
66-
protected ObjectMapper objectMapper = new ObjectMapper();
66+
protected JsonMapper jsonMapper = JsonMapper.builder().build();
6767

6868
private static final Logger LOGGER = LoggerFactory.getLogger(TaskExecutionAgent.class);
6969

@@ -99,7 +99,7 @@ protected TaskExecutionAgent(ChatClient chatClient,
9999
@Nullable Predicate<String> toolFilter,
100100
@Nullable String name,
101101
@Nullable ObservationRegistry observationRegistry,
102-
@Nullable ObjectMapper objectMapper
102+
@Nullable JsonMapper jsonMapper
103103
) {
104104
super(chatClient, observationRegistry);
105105
this.promptTemplate = promptTemplate;
@@ -113,8 +113,8 @@ protected TaskExecutionAgent(ChatClient chatClient,
113113
if (name != null) {
114114
this.name = name;
115115
}
116-
if (objectMapper != null) {
117-
this.objectMapper = objectMapper;
116+
if (jsonMapper != null) {
117+
this.jsonMapper = jsonMapper;
118118
}
119119
}
120120

@@ -237,7 +237,7 @@ protected ToolCallbackProvider getToolCallbackProvider() {
237237
for (var serverParameters : stdioProperties.toServerParameters()
238238
.entrySet()) {
239239
var transport = new StdioClientTransport(serverParameters.getValue(),
240-
new JacksonMcpJsonMapper(objectMapper));
240+
new JacksonMcpJsonMapper(jsonMapper));
241241
transports.add(new NamedClientMcpTransport(serverParameters.getKey(),
242242
transport));
243243
}
@@ -252,7 +252,7 @@ protected ToolCallbackProvider getToolCallbackProvider() {
252252
"/sse");
253253
var transport = HttpClientSseClientTransport.builder(baseUrl)
254254
.sseEndpoint(sseEndpoint)
255-
.jsonMapper(new JacksonMcpJsonMapper(objectMapper))
255+
.jsonMapper(new JacksonMcpJsonMapper(jsonMapper))
256256
.build();
257257
transports.add(new NamedClientMcpTransport(serverParameters.getKey(), transport));
258258
}
@@ -267,7 +267,7 @@ protected ToolCallbackProvider getToolCallbackProvider() {
267267
"/mcp");
268268
var transport = HttpClientStreamableHttpTransport.builder(baseUrl)
269269
.endpoint(endpoint)
270-
.jsonMapper(new JacksonMcpJsonMapper(objectMapper))
270+
.jsonMapper(new JacksonMcpJsonMapper(jsonMapper))
271271
.build();
272272
transports.add(new NamedClientMcpTransport(serverParameters.getKey(), transport));
273273
}
@@ -320,7 +320,7 @@ T chatClientRequestSpecUpdater(
320320

321321
T toolFilter(Predicate<String> toolFilter);
322322

323-
T objectMapper(ObjectMapper objectMapper);
323+
T jsonMapper(JsonMapper jsonMapper);
324324

325325
TaskExecutionAgent<Request, Response> build();
326326
}

‎patterns/task-execution/src/test/java/com/javaaidev/agenticpatterns/taskexecution/TaskExecutionAgentBuilderTest.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@
88
import org.junit.jupiter.api.Test;
99
import org.springframework.ai.chat.client.ChatClient;
1010
import org.springframework.ai.openai.OpenAiChatModel;
11-
import org.springframework.ai.openai.api.OpenAiApi;
1211

1312
@Disabled
1413
class TaskExecutionAgentBuilderTest {
1514

1615
private final ChatClient chatClient = ChatClient.builder(
17-
OpenAiChatModel.builder()
18-
.openAiApi(OpenAiApi.builder()
19-
.apiKey(System.getenv("OPENAI_API_KEY"))
20-
.build())
21-
.build()).build();
16+
OpenAiChatModel.builder().build()).build();
2217

2318
@Test
2419
void testBuilder() {

‎pom.xml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
<maven.compiler.source>${java.version}</maven.compiler.source>
5353
<maven.compiler.target>${java.version}</maven.compiler.target>
5454
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
55-
<spring-ai.version>1.1.7</spring-ai.version>
56-
<micrometer.version>1.14.4</micrometer.version>
55+
<spring-ai.version>2.0.0-M7</spring-ai.version>
56+
<micrometer.version>1.16.5</micrometer.version>
5757
</properties>
5858

5959
<dependencyManagement>
@@ -78,7 +78,7 @@
7878
<dependency>
7979
<groupId>io.micrometer</groupId>
8080
<artifactId>micrometer-tracing-bridge-otel</artifactId>
81-
<version>1.5.5</version>
81+
<version>1.6.5</version>
8282
</dependency>
8383
<dependency>
8484
<groupId>org.slf4j</groupId>

0 commit comments

Comments
 (0)