This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr-mcp.git
The following commit(s) were added to refs/heads/main by this push:
new 91284bb4 refactor: inject JsonMapper instead of ObjectMapper (#276)
91284bb4 is described below
commit 91284bb46c6fb3c216824c9e838685434cad5241
Author: Aditya Parikh <[email protected]>
AuthorDate: Mon Oct 26 15:31:15 2026 -0400
refactor: inject JsonMapper instead of ObjectMapper (#276)
Spring Boot 4's JacksonAutoConfiguration publishes format-specific mapper
beans: JsonMapper always, plus XmlMapper and CBORMapper when
jackson-dataformat-xml or jackson-dataformat-cbor is on the classpath. None
is @Primary and all extend ObjectMapper, so injecting ObjectMapper only
resolves while JsonMapper is the sole candidate; adding either dataformat
would fail startup with NoUniqueBeanDefinitionException.
Every injection point and field here relies on JSON, so declare JsonMapper.
Tests construct JsonMapper.builder().build() in place of new ObjectMapper().
Signed-off-by: Aditya Parikh <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
.../solr/mcp/server/collection/CollectionService.java | 8 ++++----
.../solr/mcp/server/config/JsonResponseParser.java | 6 +++---
.../org/apache/solr/mcp/server/config/SolrConfig.java | 4 ++--
.../indexing/documentcreator/JsonDocumentCreator.java | 8 ++++----
.../indexing/documentcreator/SolrDocumentCreator.java | 2 +-
.../org/apache/solr/mcp/server/schema/SchemaService.java | 8 ++++----
.../solr/mcp/server/McpClientIntegrationTestBase.java | 3 +--
.../java/org/apache/solr/mcp/server/TestDocuments.java | 3 +--
.../solr/mcp/server/config/SolrConfigAuthTest.java | 4 ++--
.../documentcreator/JsonDocumentCreatorTest.java | 3 +--
.../solr/mcp/server/observability/LgtmAssertions.java | 6 +++---
.../server/observability/OtlpExportIntegrationTest.java | 4 ++--
.../apache/solr/mcp/server/schema/SchemaServiceTest.java | 16 ++++++++--------
13 files changed, 36 insertions(+), 39 deletions(-)
diff --git
a/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java
b/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java
index aac8d277..438839dd 100644
--- a/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java
+++ b/src/main/java/org/apache/solr/mcp/server/collection/CollectionService.java
@@ -56,7 +56,7 @@ import org.springframework.ai.mcp.annotation.McpTool;
import org.springframework.ai.mcp.annotation.McpToolParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
-import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
/**
* Spring Service providing comprehensive Solr collection management and
monitoring capabilities for
@@ -265,7 +265,7 @@ public class CollectionService {
/** SolrJ client for communicating with Solr server */
private final SolrClient solrClient;
- private final ObjectMapper objectMapper;
+ private final JsonMapper objectMapper;
/**
* Constructs a new CollectionService with the required dependencies.
@@ -274,11 +274,11 @@ public class CollectionService {
* application startup.
*
* @param solrClient the SolrJ client instance for communicating with Solr
- * @param objectMapper the Jackson ObjectMapper for JSON serialization
+ * @param objectMapper the Jackson JsonMapper for JSON serialization
* @see SolrClient
* @see SolrConfigurationProperties
*/
- public CollectionService(SolrClient solrClient, ObjectMapper objectMapper) {
+ public CollectionService(SolrClient solrClient, JsonMapper objectMapper) {
this.solrClient = solrClient;
this.objectMapper = objectMapper;
}
diff --git
a/src/main/java/org/apache/solr/mcp/server/config/JsonResponseParser.java
b/src/main/java/org/apache/solr/mcp/server/config/JsonResponseParser.java
index 79c440c4..09d27051 100644
--- a/src/main/java/org/apache/solr/mcp/server/config/JsonResponseParser.java
+++ b/src/main/java/org/apache/solr/mcp/server/config/JsonResponseParser.java
@@ -30,7 +30,7 @@ import org.jspecify.annotations.Nullable;
import org.springframework.http.MediaType;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.JsonNode;
-import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
/**
* SolrJ {@link ResponseParser} that requests JSON wire format ({@code
wt=json}) and converts the
@@ -64,9 +64,9 @@ import tools.jackson.databind.ObjectMapper;
*/
class JsonResponseParser extends ResponseParser {
- private final ObjectMapper mapper;
+ private final JsonMapper mapper;
- JsonResponseParser(ObjectMapper mapper) {
+ JsonResponseParser(JsonMapper mapper) {
this.mapper = mapper;
}
diff --git a/src/main/java/org/apache/solr/mcp/server/config/SolrConfig.java
b/src/main/java/org/apache/solr/mcp/server/config/SolrConfig.java
index 45737c77..48df20e6 100644
--- a/src/main/java/org/apache/solr/mcp/server/config/SolrConfig.java
+++ b/src/main/java/org/apache/solr/mcp/server/config/SolrConfig.java
@@ -25,7 +25,7 @@ import
org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
-import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
/**
* Spring Configuration class for Apache Solr client setup and connection
management.
@@ -158,7 +158,7 @@ public class SolrConfig {
* @return the JSON response parser
*/
@Bean
- JsonResponseParser jsonResponseParser(ObjectMapper objectMapper) {
+ JsonResponseParser jsonResponseParser(JsonMapper objectMapper) {
return new JsonResponseParser(objectMapper);
}
diff --git
a/src/main/java/org/apache/solr/mcp/server/indexing/documentcreator/JsonDocumentCreator.java
b/src/main/java/org/apache/solr/mcp/server/indexing/documentcreator/JsonDocumentCreator.java
index 62080b8c..c48145d4 100644
---
a/src/main/java/org/apache/solr/mcp/server/indexing/documentcreator/JsonDocumentCreator.java
+++
b/src/main/java/org/apache/solr/mcp/server/indexing/documentcreator/JsonDocumentCreator.java
@@ -24,7 +24,7 @@ import org.apache.solr.common.SolrInputDocument;
import org.springframework.stereotype.Component;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.JsonNode;
-import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
/**
* Utility class for processing JSON documents and converting them to
SolrInputDocument objects.
@@ -35,14 +35,14 @@ import tools.jackson.databind.ObjectMapper;
@Component
public class JsonDocumentCreator implements SolrDocumentCreator {
- private final ObjectMapper objectMapper;
+ private final JsonMapper objectMapper;
/**
- * Constructs the creator with the Jackson {@link ObjectMapper} used to
parse incoming JSON.
+ * Constructs the creator with the Jackson {@link JsonMapper} used to parse
incoming JSON.
*
* @param objectMapper the JSON parser injected by Spring
*/
- public JsonDocumentCreator(ObjectMapper objectMapper) {
+ public JsonDocumentCreator(JsonMapper objectMapper) {
this.objectMapper = objectMapper;
}
diff --git
a/src/main/java/org/apache/solr/mcp/server/indexing/documentcreator/SolrDocumentCreator.java
b/src/main/java/org/apache/solr/mcp/server/indexing/documentcreator/SolrDocumentCreator.java
index dd4e4de7..9e6479f1 100644
---
a/src/main/java/org/apache/solr/mcp/server/indexing/documentcreator/SolrDocumentCreator.java
+++
b/src/main/java/org/apache/solr/mcp/server/indexing/documentcreator/SolrDocumentCreator.java
@@ -46,7 +46,7 @@ import org.apache.solr.common.SolrInputDocument;
* <p><strong>Usage Example:</strong>
*
* <pre>{@code
- * SolrDocumentCreator creator = new JsonDocumentCreator(new ObjectMapper());
+ * SolrDocumentCreator creator = new
JsonDocumentCreator(JsonMapper.builder().build());
* String jsonData = "[{\"title\":\"Document 1\",\"content\":\"Content
here\"}]";
* List<SolrInputDocument> documents = creator.create(jsonData);
* }</pre>
diff --git a/src/main/java/org/apache/solr/mcp/server/schema/SchemaService.java
b/src/main/java/org/apache/solr/mcp/server/schema/SchemaService.java
index cda33227..c7bb39d8 100644
--- a/src/main/java/org/apache/solr/mcp/server/schema/SchemaService.java
+++ b/src/main/java/org/apache/solr/mcp/server/schema/SchemaService.java
@@ -42,7 +42,7 @@ import org.springframework.ai.mcp.annotation.McpTool;
import org.springframework.ai.mcp.annotation.McpToolParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
-import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
/**
* Spring Service providing schema introspection and management capabilities
for Apache Solr
@@ -122,7 +122,7 @@ public class SchemaService {
/** SolrJ client for communicating with Solr server */
private final SolrClient solrClient;
- private final ObjectMapper objectMapper;
+ private final JsonMapper objectMapper;
/**
* Constructs a new SchemaService with the required dependencies.
@@ -132,10 +132,10 @@ public class SchemaService {
* operations.
*
* @param solrClient the SolrJ client instance for communicating with Solr
- * @param objectMapper the Jackson ObjectMapper for JSON serialization
+ * @param objectMapper the Jackson JsonMapper for JSON serialization
* @see SolrClient
*/
- public SchemaService(SolrClient solrClient, ObjectMapper objectMapper) {
+ public SchemaService(SolrClient solrClient, JsonMapper objectMapper) {
this.solrClient = solrClient;
this.objectMapper = objectMapper;
}
diff --git
a/src/test/java/org/apache/solr/mcp/server/McpClientIntegrationTestBase.java
b/src/test/java/org/apache/solr/mcp/server/McpClientIntegrationTestBase.java
index bacd8506..7d153d2a 100644
--- a/src/test/java/org/apache/solr/mcp/server/McpClientIntegrationTestBase.java
+++ b/src/test/java/org/apache/solr/mcp/server/McpClientIntegrationTestBase.java
@@ -47,7 +47,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import tools.jackson.core.type.TypeReference;
-import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
/**
@@ -69,7 +68,7 @@ public abstract class McpClientIntegrationTestBase {
*/
protected static final int SHOWS_DOC_COUNT = 61;
- protected static final ObjectMapper OBJECT_MAPPER =
JsonMapper.builder().build();
+ protected static final JsonMapper OBJECT_MAPPER =
JsonMapper.builder().build();
@AutoClose
@SuppressWarnings("NotNullFieldNotInitialized") // set by beforeAll()
diff --git a/src/test/java/org/apache/solr/mcp/server/TestDocuments.java
b/src/test/java/org/apache/solr/mcp/server/TestDocuments.java
index 9bec38e8..d0c22def 100644
--- a/src/test/java/org/apache/solr/mcp/server/TestDocuments.java
+++ b/src/test/java/org/apache/solr/mcp/server/TestDocuments.java
@@ -20,7 +20,6 @@ import java.util.List;
import java.util.Map;
import tools.jackson.core.JacksonException;
import tools.jackson.core.type.TypeReference;
-import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
/**
@@ -30,7 +29,7 @@ import tools.jackson.databind.json.JsonMapper;
*/
public final class TestDocuments {
- private static final ObjectMapper OBJECT_MAPPER =
JsonMapper.builder().build();
+ private static final JsonMapper OBJECT_MAPPER = JsonMapper.builder().build();
private static final TypeReference<List<Map<String, Object>>> DOCUMENTS =
new TypeReference<>() {};
diff --git
a/src/test/java/org/apache/solr/mcp/server/config/SolrConfigAuthTest.java
b/src/test/java/org/apache/solr/mcp/server/config/SolrConfigAuthTest.java
index 2efa4036..e4624628 100644
--- a/src/test/java/org/apache/solr/mcp/server/config/SolrConfigAuthTest.java
+++ b/src/test/java/org/apache/solr/mcp/server/config/SolrConfigAuthTest.java
@@ -33,7 +33,7 @@ import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
import org.springframework.util.ReflectionUtils;
-import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
/**
* Unit tests for the optional HTTP Basic Authentication wiring performed by
{@link SolrConfig}.
@@ -49,7 +49,7 @@ import tools.jackson.databind.ObjectMapper;
@DisabledInNativeImage
class SolrConfigAuthTest {
- @Autowired private ObjectMapper objectMapper;
+ @Autowired private JsonMapper objectMapper;
@Test
void noCredentialsWhenBothMissing() throws Exception {
diff --git
a/src/test/java/org/apache/solr/mcp/server/indexing/documentcreator/JsonDocumentCreatorTest.java
b/src/test/java/org/apache/solr/mcp/server/indexing/documentcreator/JsonDocumentCreatorTest.java
index bcd3024f..ff7e968a 100644
---
a/src/test/java/org/apache/solr/mcp/server/indexing/documentcreator/JsonDocumentCreatorTest.java
+++
b/src/test/java/org/apache/solr/mcp/server/indexing/documentcreator/JsonDocumentCreatorTest.java
@@ -26,7 +26,6 @@ import java.util.Map;
import java.util.TreeMap;
import org.apache.solr.common.SolrInputDocument;
import org.junit.jupiter.api.Test;
-import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
/**
@@ -37,7 +36,7 @@ import tools.jackson.databind.json.JsonMapper;
*/
class JsonDocumentCreatorTest {
- private final ObjectMapper objectMapper = JsonMapper.builder().build();
+ private final JsonMapper objectMapper = JsonMapper.builder().build();
private final JsonDocumentCreator creator = new
JsonDocumentCreator(objectMapper);
diff --git
a/src/test/java/org/apache/solr/mcp/server/observability/LgtmAssertions.java
b/src/test/java/org/apache/solr/mcp/server/observability/LgtmAssertions.java
index 6559b386..c2039ef7 100644
--- a/src/test/java/org/apache/solr/mcp/server/observability/LgtmAssertions.java
+++ b/src/test/java/org/apache/solr/mcp/server/observability/LgtmAssertions.java
@@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestClient;
import org.testcontainers.grafana.LgtmStackContainer;
import tools.jackson.databind.JsonNode;
-import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
/**
* Helper class to query LGTM stack backends (Tempo, Prometheus, Loki).
@@ -53,11 +53,11 @@ public class LgtmAssertions {
private final LgtmStackContainer lgtm;
- private final ObjectMapper objectMapper;
+ private final JsonMapper objectMapper;
private final RestClient restClient;
- public LgtmAssertions(LgtmStackContainer lgtm, ObjectMapper objectMapper) {
+ public LgtmAssertions(LgtmStackContainer lgtm, JsonMapper objectMapper) {
this.lgtm = lgtm;
this.objectMapper = objectMapper;
this.restClient = RestClient.create();
diff --git
a/src/test/java/org/apache/solr/mcp/server/observability/OtlpExportIntegrationTest.java
b/src/test/java/org/apache/solr/mcp/server/observability/OtlpExportIntegrationTest.java
index b7491544..13da7172 100644
---
a/src/test/java/org/apache/solr/mcp/server/observability/OtlpExportIntegrationTest.java
+++
b/src/test/java/org/apache/solr/mcp/server/observability/OtlpExportIntegrationTest.java
@@ -42,7 +42,7 @@ import org.testcontainers.grafana.LgtmStackContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import tools.jackson.databind.JsonNode;
-import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
/**
* Integration test verifying that observability signals (traces, metrics,
logs) are exported via
@@ -100,7 +100,7 @@ class OtlpExportIntegrationTest {
@Autowired private SolrClient solrClient;
- @Autowired private ObjectMapper objectMapper;
+ @Autowired private JsonMapper objectMapper;
@BeforeAll
static void setUpCollection(@Autowired SolrClient solrClient) throws
Exception {
diff --git
a/src/test/java/org/apache/solr/mcp/server/schema/SchemaServiceTest.java
b/src/test/java/org/apache/solr/mcp/server/schema/SchemaServiceTest.java
index d36670ef..a4b5ba3e 100644
--- a/src/test/java/org/apache/solr/mcp/server/schema/SchemaServiceTest.java
+++ b/src/test/java/org/apache/solr/mcp/server/schema/SchemaServiceTest.java
@@ -38,7 +38,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import tools.jackson.databind.ObjectMapper;
+import tools.jackson.databind.json.JsonMapper;
/**
* Comprehensive test suite for the SchemaService class. Tests schema
retrieval functionality with
@@ -50,7 +50,7 @@ class SchemaServiceTest {
@Mock private SolrClient solrClient;
- @Mock private ObjectMapper objectMapper;
+ @Mock private JsonMapper objectMapper;
private SchemaService schemaService;
@@ -213,8 +213,8 @@ class SchemaServiceTest {
@Test
void addFieldTypes_happyPathWithAnalyzer_buildsCorrectFieldTypeDefinition()
throws Exception {
- // Use a real ObjectMapper so convertValue actually works
- ObjectMapper realMapper = new ObjectMapper();
+ // Use a real JsonMapper so convertValue actually works
+ JsonMapper realMapper = JsonMapper.builder().build();
SchemaService service = new SchemaService(solrClient, realMapper);
List<Map<String, Object>> types =
@@ -244,7 +244,7 @@ class SchemaServiceTest {
@Test
void addFieldTypes_separateAnalyzers_buildsCorrectFieldTypeDefinition()
throws Exception {
- ObjectMapper realMapper = new ObjectMapper();
+ JsonMapper realMapper = JsonMapper.builder().build();
SchemaService service = new SchemaService(solrClient, realMapper);
List<Map<String, Object>> types =
@@ -284,7 +284,7 @@ class SchemaServiceTest {
@Test
void addFieldTypes_denseVectorField_noAnalyzer() throws Exception {
- ObjectMapper realMapper = new ObjectMapper();
+ JsonMapper realMapper = JsonMapper.builder().build();
SchemaService service = new SchemaService(solrClient, realMapper);
List<Map<String, Object>> types =
@@ -310,7 +310,7 @@ class SchemaServiceTest {
@Test
void addFieldTypes_solrThrows_propagates() throws Exception {
- ObjectMapper realMapper = new ObjectMapper();
+ JsonMapper realMapper = JsonMapper.builder().build();
SchemaService service = new SchemaService(solrClient, realMapper);
when(solrClient.request(any(SolrRequest.class), eq("col")))
@@ -331,7 +331,7 @@ class SchemaServiceTest {
*/
@Test
void addFieldTypes_analyzerWithOnlyClassKey_preservesClassInWireFormat()
throws Exception {
- ObjectMapper realMapper = new ObjectMapper();
+ JsonMapper realMapper = JsonMapper.builder().build();
SchemaService service = new SchemaService(solrClient, realMapper);
List<Map<String, Object>> types =