Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
upd javadoc
  • Loading branch information
rashtao committed Apr 4, 2024
commit d368902fc1446051144e61ade663fd7a2b72634c
2 changes: 1 addition & 1 deletion core/src/main/java/com/arangodb/serde/ArangoSerde.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface ArangoSerde {
*
* @param content byte array to deserialize
* @param clazz class of target data type
* @param ctx serde context
* @param ctx serde context, cannot be null
* @return deserialized object
*/
default <T> T deserialize(byte[] content, Class<T> clazz, SerdeContext ctx) {
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/com/arangodb/serde/SerdeContext.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.arangodb.serde;

/**
* Context holding information about the current request and response.
*/
public interface SerdeContext {
/**
* @return the stream transaction id of the request (if any) or {@code null}
*/
String getStreamTransactionId();
}
3 changes: 3 additions & 0 deletions driver/src/test/java/com/arangodb/SerdeContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import java.io.IOException;
import java.util.Collections;
import java.util.Objects;

import static com.arangodb.util.TestUtils.TEST_DB;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -70,6 +71,8 @@ public <T> T deserialize(byte[] content, Class<T> clazz) {

@Override
public <T> T deserialize(byte[] content, Class<T> clazz, SerdeContext ctx) {
Objects.requireNonNull(ctx);

if (clazz != Person.class) {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.arangodb.serde.jackson.internal;

import com.arangodb.internal.serde.SerdeContextImpl;
import com.arangodb.serde.SerdeContext;
import com.arangodb.serde.jackson.JacksonSerde;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -8,6 +9,7 @@
import com.fasterxml.jackson.databind.cfg.ContextAttributes;

import java.io.IOException;
import java.util.Objects;
import java.util.function.Consumer;

import static com.arangodb.internal.serde.SerdeUtils.SERDE_CONTEXT_ATTRIBUTE_NAME;
Expand Down Expand Up @@ -36,15 +38,12 @@ public byte[] serialize(final Object value) {

@Override
public <T> T deserialize(final byte[] content, final Class<T> type) {
try {
return mapper.readerFor(mapper.constructType(type)).readValue(content);
} catch (IOException e) {
throw new RuntimeException(e);
}
return deserialize(content, type, SerdeContextImpl.EMPTY);
}

@Override
public <T> T deserialize(byte[] content, Class<T> type, SerdeContext ctx) {
Objects.requireNonNull(ctx);
try {
return mapper.readerFor(mapper.constructType(type))
.with(ContextAttributes.getEmpty().withPerCallAttribute(SERDE_CONTEXT_ATTRIBUTE_NAME, ctx))
Expand Down