Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions memind-clients/java/memind-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package com.openmemind.ai.client;

import com.fasterxml.jackson.core.type.TypeReference;
import tools.jackson.core.type.TypeReference;
import com.openmemind.ai.client.exception.MemindClientException;
import com.openmemind.ai.client.internal.ApiResult;
import com.openmemind.ai.client.internal.MemindHttpClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package com.openmemind.ai.client.exception;

import com.fasterxml.jackson.databind.JsonNode;
import tools.jackson.databind.JsonNode;

public class MemindApiException extends MemindClientException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package com.openmemind.ai.client.internal;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import tools.jackson.databind.JsonNode;

@JsonIgnoreProperties(ignoreUnknown = true)
record ErrorResult(ApiError error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
package com.openmemind.ai.client.internal;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.openmemind.ai.client.exception.MemindApiException;
import com.openmemind.ai.client.exception.MemindConnectionException;
import com.openmemind.ai.client.exception.MemindTimeoutException;
import tools.jackson.core.JacksonException;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.DeserializationFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.cfg.DateTimeFeature;
import tools.jackson.databind.json.JsonMapper;
import java.io.IOException;
import java.net.ConnectException;
import java.net.URI;
Expand Down Expand Up @@ -56,12 +57,7 @@ public MemindHttpClient(
HttpClient.newBuilder()
.connectTimeout(Objects.requireNonNull(connectTimeout, "connectTimeout"))
.build();
this.objectMapper =
new ObjectMapper()
.registerModule(new JavaTimeModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
this.objectMapper = createObjectMapper();
}

public <T> CompletableFuture<T> get(String path, TypeReference<ApiResult<T>> responseType) {
Expand All @@ -80,7 +76,7 @@ public <T> CompletableFuture<T> post(
.build();
log.debug("POST {}", request.uri());
return sendAsync(request, responseType);
} catch (IOException e) {
} catch (JacksonException e) {
return CompletableFuture.failedFuture(
new MemindConnectionException("Failed to serialize request body", e));
}
Expand Down Expand Up @@ -140,7 +136,7 @@ private <T> T handleResponse(
throw toApiException(status, body, requestId(response));
} catch (MemindApiException e) {
throw e;
} catch (IOException e) {
} catch (JacksonException e) {
throw new MemindApiException(
status,
"parse_error",
Expand All @@ -150,8 +146,7 @@ private <T> T handleResponse(
}
}

private MemindApiException toApiException(int status, byte[] body, String requestId)
throws IOException {
private MemindApiException toApiException(int status, byte[] body, String requestId) {
ErrorResult errorResult = objectMapper.readValue(body, ErrorResult.class);
ErrorResult.ApiError error = errorResult.error();
if (error == null) {
Expand All @@ -169,6 +164,19 @@ public ObjectMapper getObjectMapper() {
return objectMapper;
}

private static ObjectMapper createObjectMapper() {
ObjectMapper mapper =
JsonMapper.builder()
.disable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.changeDefaultPropertyInclusion(
inclusion ->
inclusion.withValueInclusion(
JsonInclude.Include.NON_NULL))
.build();
return mapper;
}

@Override
public void close() {
// JDK HttpClient does not require explicit close in Java 17.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@
*/
package com.openmemind.ai.client.internal;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.openmemind.ai.client.model.common.ConversationContent;
import com.openmemind.ai.client.model.common.MapRawContent;
import com.openmemind.ai.client.model.common.RawContent;
import java.io.IOException;
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonGenerator;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.ValueSerializer;

public class RawContentSerializer extends JsonSerializer<RawContent> {
public class RawContentSerializer extends ValueSerializer<RawContent> {

@Override
public void serialize(RawContent value, JsonGenerator gen, SerializerProvider provider)
throws IOException {
public void serialize(RawContent value, JsonGenerator gen, SerializationContext context)
throws JacksonException {
gen.writeStartObject();
gen.writeStringField("type", value.type());
gen.writeStringProperty("type", value.type());

if (value instanceof ConversationContent conv) {
gen.writeObjectField("messages", conv.getMessages());
context.defaultSerializeProperty("messages", conv.getMessages(), gen);
} else if (value instanceof MapRawContent map) {
for (var entry : map.getProperties().entrySet()) {
gen.writeObjectField(entry.getKey(), entry.getValue());
context.defaultSerializeProperty(entry.getKey(), entry.getValue(), gen);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package com.openmemind.ai.client.model.common;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import tools.jackson.databind.annotation.JsonSerialize;
import com.openmemind.ai.client.internal.RawContentSerializer;

@JsonSerialize(using = RawContentSerializer.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.fasterxml.jackson.core.type.TypeReference;
import tools.jackson.core.type.TypeReference;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
import com.openmemind.ai.client.exception.MemindApiException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.cfg.DateTimeFeature;
import tools.jackson.databind.json.JsonMapper;
import java.time.Instant;
import org.junit.jupiter.api.Test;

class MessageTest {

private final ObjectMapper mapper =
new ObjectMapper()
.registerModule(new JavaTimeModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
JsonMapper.builder().disable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS).build();

@Test
void userMessage_serializesCorrectly() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.cfg.DateTimeFeature;
import tools.jackson.databind.json.JsonMapper;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;

class RawContentSerializerTest {

private final ObjectMapper mapper =
new ObjectMapper()
.registerModule(new JavaTimeModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
JsonMapper.builder().disable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS).build();

@Test
void conversationContent_serializesWithRegisteredTypeField() throws Exception {
Expand Down
4 changes: 0 additions & 4 deletions memind-evaluation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
package com.openmemind.ai.memory.evaluation.checkpoint;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.openmemind.ai.memory.evaluation.adapter.model.SearchResult;
import com.openmemind.ai.memory.evaluation.pipeline.Stage;
import com.openmemind.ai.memory.evaluation.pipeline.model.AnswerResult;
Expand All @@ -28,6 +26,9 @@
import java.util.concurrent.locks.ReentrantLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.jackson.core.JacksonException;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;

/**
* Evaluation checkpoint persistence storage, responsible for reading and writing JSON files for checkpoint / search / answer stages
Expand Down Expand Up @@ -64,7 +65,7 @@ public CheckpointState load(String dataset, String runName) {
state.completedAddConvIds().size(),
state.completedStages().size());
return state;
} catch (IOException e) {
} catch (JacksonException e) {
log.warn("Failed to read checkpoint, starting fresh: {}", e.getMessage());
}
}
Expand All @@ -86,7 +87,7 @@ public boolean isStageCompleted(Path runDir, Stage stage) {
try {
CheckpointState state = mapper.readValue(path.toFile(), CheckpointState.class);
return state.isStageCompleted(stage.name());
} catch (IOException e) {
} catch (JacksonException e) {
log.warn("Failed to read checkpoint: {}", e.getMessage());
return false;
}
Expand All @@ -98,7 +99,7 @@ public void markStageCompleted(Path runDir, Stage stage) {
if (Files.exists(path)) {
try {
state = mapper.readValue(path.toFile(), CheckpointState.class);
} catch (IOException e) {
} catch (JacksonException e) {
log.warn("Failed to read checkpoint, creating new: {}", e.getMessage());
state = new CheckpointState();
}
Expand All @@ -117,7 +118,7 @@ public Map<String, List<SearchResult>> loadSearchCheckpoint(Path runDir) {
try {
return mapper.readValue(
path.toFile(), new TypeReference<Map<String, List<SearchResult>>>() {});
} catch (IOException e) {
} catch (JacksonException e) {
log.warn("Failed to read search checkpoint: {}", e.getMessage());
}
}
Expand All @@ -140,7 +141,7 @@ public Map<String, AnswerResult> loadAnswerCheckpoint(Path runDir) {
try {
return mapper.readValue(
path.toFile(), new TypeReference<Map<String, AnswerResult>>() {});
} catch (IOException e) {
} catch (JacksonException e) {
log.warn("Failed to read answer checkpoint: {}", e.getMessage());
}
}
Expand All @@ -162,7 +163,7 @@ public List<SearchResult> loadSearchResults(Path runDir) {
if (Files.exists(path)) {
try {
return mapper.readValue(path.toFile(), new TypeReference<List<SearchResult>>() {});
} catch (IOException e) {
} catch (JacksonException e) {
log.warn("Failed to read search results: {}", e.getMessage());
}
}
Expand All @@ -178,7 +179,7 @@ public List<AnswerResult> loadAnswerResults(Path runDir) {
if (Files.exists(path)) {
try {
return mapper.readValue(path.toFile(), new TypeReference<List<AnswerResult>>() {});
} catch (IOException e) {
} catch (JacksonException e) {
log.warn("Failed to read answer results: {}", e.getMessage());
}
}
Expand All @@ -204,7 +205,7 @@ private void saveFile(Path path, Object data) {
mapper.writeValue(tmp.toFile(), data);
Files.move(
tmp, path, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
} catch (IOException | JacksonException e) {
log.error("Failed to save file {}: {}", path, e.getMessage());
} finally {
lock.unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
*/
package com.openmemind.ai.memory.evaluation.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.openmemind.ai.memory.evaluation.checkpoint.CheckpointStore;
import io.netty.channel.ChannelOption;
import java.time.Duration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;
import reactor.netty.resources.ConnectionProvider;
import tools.jackson.databind.ObjectMapper;

/**
* Evaluation-specific infrastructure configuration.
Expand All @@ -37,12 +35,6 @@ public class EvaluationConfiguration {

// ─── Infrastructure ─────────────────────────────

@Bean
@Primary
public ObjectMapper objectMapper() {
return new ObjectMapper().registerModule(new JavaTimeModule());
}

@Bean
public CheckpointStore checkpointStore(ObjectMapper mapper, EvaluationProperties props) {
return new CheckpointStore(mapper, java.nio.file.Path.of(props.getOutputDir()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
package com.openmemind.ai.memory.evaluation.dataset.converter;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
Expand All @@ -29,6 +27,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;

/**
* Convert LongMemEval format dataset to LoCoMo JSON format
Expand Down
Loading
Loading