From 7a4d59e49281890f572aa0633796da8896ae3b30 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 9 Jan 2025 13:39:13 +0100 Subject: [PATCH 1/4] include serde tests in shaded tests --- test-functional/pom.xml | 18 +++++++++++++++--- .../java/com/arangodb/HttpProxyTest.java | 2 +- .../arangodb/JacksonRequestContextTest.java | 2 +- .../java/com/arangodb/RequestContextTest.java | 2 +- .../arangodb/serde/CustomSerdeAsyncTest.java | 2 +- .../com/arangodb/serde/CustomSerdeTest.java | 2 +- .../serde/JacksonInterferenceTest.java | 3 +++ 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/test-functional/pom.xml b/test-functional/pom.xml index e59429e27..0c802aaa8 100644 --- a/test-functional/pom.xml +++ b/test-functional/pom.xml @@ -34,11 +34,11 @@ **/CustomSerdeTest.**, - **/SerdeTest.**, - **/SerializableTest.**, + **/CustomSerdeAsyncTest.**, **/JacksonInterferenceTest.**, **/JacksonRequestContextTest.**, - **/HttpProxyTest.** + **/HttpProxyTest.**, + **/RequestContextTest.** @@ -49,6 +49,18 @@ com.fasterxml.jackson.databind.ObjectNode com.arangodb.shaded.fasterxml.jackson.databind.ObjectNode + + com.fasterxml.jackson.databind.node + com.arangodb.shaded.fasterxml.jackson.databind.node + + + com.fasterxml.jackson.databind.ObjectMapper + com.arangodb.shaded.fasterxml.jackson.databind.ObjectMapper + + + com.fasterxml.jackson.core.JsonProcessingException + com.arangodb.shaded.fasterxml.jackson.core.JsonProcessingException + diff --git a/test-functional/src/test-ssl/java/com/arangodb/HttpProxyTest.java b/test-functional/src/test-ssl/java/com/arangodb/HttpProxyTest.java index 32305f526..2e74a1fb0 100644 --- a/test-functional/src/test-ssl/java/com/arangodb/HttpProxyTest.java +++ b/test-functional/src/test-ssl/java/com/arangodb/HttpProxyTest.java @@ -36,7 +36,7 @@ /** - * @author Michele Rastelli + * NB: excluded from shaded tests */ class HttpProxyTest extends BaseTest { diff --git a/test-functional/src/test/java/com/arangodb/JacksonRequestContextTest.java b/test-functional/src/test/java/com/arangodb/JacksonRequestContextTest.java index a1152c402..ea82b52d1 100644 --- a/test-functional/src/test/java/com/arangodb/JacksonRequestContextTest.java +++ b/test-functional/src/test/java/com/arangodb/JacksonRequestContextTest.java @@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * @author Michele Rastelli + * NB: excluded from shaded tests */ class JacksonRequestContextTest { diff --git a/test-functional/src/test/java/com/arangodb/RequestContextTest.java b/test-functional/src/test/java/com/arangodb/RequestContextTest.java index 730dea14d..f76a0fd3d 100644 --- a/test-functional/src/test/java/com/arangodb/RequestContextTest.java +++ b/test-functional/src/test/java/com/arangodb/RequestContextTest.java @@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** - * @author Michele Rastelli + * NB: excluded from shaded tests */ class RequestContextTest { diff --git a/test-functional/src/test/java/com/arangodb/serde/CustomSerdeAsyncTest.java b/test-functional/src/test/java/com/arangodb/serde/CustomSerdeAsyncTest.java index 1b5fb9d54..0f305e97c 100644 --- a/test-functional/src/test/java/com/arangodb/serde/CustomSerdeAsyncTest.java +++ b/test-functional/src/test/java/com/arangodb/serde/CustomSerdeAsyncTest.java @@ -50,7 +50,7 @@ /** - * @author Michele Rastelli + * NB: excluded from shaded tests */ class CustomSerdeAsyncTest { diff --git a/test-functional/src/test/java/com/arangodb/serde/CustomSerdeTest.java b/test-functional/src/test/java/com/arangodb/serde/CustomSerdeTest.java index bfdc37bd5..58a736f6f 100644 --- a/test-functional/src/test/java/com/arangodb/serde/CustomSerdeTest.java +++ b/test-functional/src/test/java/com/arangodb/serde/CustomSerdeTest.java @@ -49,7 +49,7 @@ /** - * @author Michele Rastelli + * NB: excluded from shaded tests */ class CustomSerdeTest { diff --git a/test-functional/src/test/java/com/arangodb/serde/JacksonInterferenceTest.java b/test-functional/src/test/java/com/arangodb/serde/JacksonInterferenceTest.java index 13f925fc9..d5a3a969c 100644 --- a/test-functional/src/test/java/com/arangodb/serde/JacksonInterferenceTest.java +++ b/test-functional/src/test/java/com/arangodb/serde/JacksonInterferenceTest.java @@ -16,6 +16,9 @@ import static org.assertj.core.api.Assertions.assertThat; +/** + * NB: excluded from shaded tests + */ class JacksonInterferenceTest { private final ObjectMapper mapper = new ObjectMapper(); From f5eaecf4ed85b25a3dcefba56151061f5fb54379 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 9 Jan 2025 14:24:26 +0100 Subject: [PATCH 2/4] added support to Jakarta JSON-B datatypes --- core/pom.xml | 5 +++ .../internal/serde/InternalSerde.java | 1 - .../internal/serde/InternalSerdeImpl.java | 12 ++++++ .../arangodb/internal/serde/SerdeUtils.java | 4 +- test-functional/pom.xml | 9 +++++ .../test/java/com/arangodb/BaseJunit5.java | 2 +- .../com/arangodb/serde/JsonBTypesTest.java | 40 +++++++++++++++++++ .../test/resources/simplelogger.properties | 1 + 8 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 test-functional/src/test/java/com/arangodb/serde/JsonBTypesTest.java diff --git a/core/pom.xml b/core/pom.xml index 2162f384f..1780d442d 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -41,6 +41,11 @@ jackson-annotations compile + + com.fasterxml.jackson.datatype + jackson-datatype-jakarta-jsonp + compile + com.google.code.findbugs jsr305 diff --git a/core/src/main/java/com/arangodb/internal/serde/InternalSerde.java b/core/src/main/java/com/arangodb/internal/serde/InternalSerde.java index 4fa4a1a06..1459e9970 100644 --- a/core/src/main/java/com/arangodb/internal/serde/InternalSerde.java +++ b/core/src/main/java/com/arangodb/internal/serde/InternalSerde.java @@ -3,7 +3,6 @@ import com.arangodb.arch.UsedInApi; import com.arangodb.serde.ArangoSerde; import com.arangodb.ContentType; -import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; diff --git a/core/src/main/java/com/arangodb/internal/serde/InternalSerdeImpl.java b/core/src/main/java/com/arangodb/internal/serde/InternalSerdeImpl.java index 3696cbc20..8bd24ba31 100644 --- a/core/src/main/java/com/arangodb/internal/serde/InternalSerdeImpl.java +++ b/core/src/main/java/com/arangodb/internal/serde/InternalSerdeImpl.java @@ -17,6 +17,10 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsonp.JSONPModule; +import jakarta.json.JsonException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -27,6 +31,7 @@ import static com.arangodb.internal.serde.SerdeUtils.extractBytes; final class InternalSerdeImpl implements InternalSerde { + private static final Logger LOG = LoggerFactory.getLogger(InternalSerdeImpl.class); static { checkSupportedJacksonVersion(); @@ -50,6 +55,13 @@ final class InternalSerdeImpl implements InternalSerde { new UserDataSerializer(this), new UserDataDeserializer(this) )); + + // JSON-P datatypes + try { + mapper.registerModule(new JSONPModule()); + } catch (JsonException e) { + LOG.debug("Jakarta JSON-P provider not found, handling of JSON-P datatypes is disabled", e); + } } @Override diff --git a/core/src/main/java/com/arangodb/internal/serde/SerdeUtils.java b/core/src/main/java/com/arangodb/internal/serde/SerdeUtils.java index 9783386c6..acbbcbaaf 100644 --- a/core/src/main/java/com/arangodb/internal/serde/SerdeUtils.java +++ b/core/src/main/java/com/arangodb/internal/serde/SerdeUtils.java @@ -13,6 +13,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.TypeFactory; +import jakarta.json.JsonValue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -127,7 +128,8 @@ public static byte[] extractBytes(JsonParser parser) throws IOException { } public static boolean isManagedClass(Class clazz) { - return JsonNode.class.isAssignableFrom(clazz) || + return JsonNode.class.isAssignableFrom(clazz) || // jackson datatypes + JsonValue.class.isAssignableFrom(clazz) || // JSON-B datatypes RawJson.class.equals(clazz) || RawBytes.class.equals(clazz) || BaseDocument.class.equals(clazz) || diff --git a/test-functional/pom.xml b/test-functional/pom.xml index 0c802aaa8..d529cea37 100644 --- a/test-functional/pom.xml +++ b/test-functional/pom.xml @@ -17,6 +17,15 @@ true + + + org.eclipse.parsson + parsson + 1.1.7 + test + + + shaded diff --git a/test-functional/src/test/java/com/arangodb/BaseJunit5.java b/test-functional/src/test/java/com/arangodb/BaseJunit5.java index c6759f07b..d5c491361 100644 --- a/test-functional/src/test/java/com/arangodb/BaseJunit5.java +++ b/test-functional/src/test/java/com/arangodb/BaseJunit5.java @@ -101,7 +101,7 @@ static ArangoDatabase initDB(String name) { return database; } - static ArangoDatabase initDB() { + protected static ArangoDatabase initDB() { return initDB(TEST_DB); } diff --git a/test-functional/src/test/java/com/arangodb/serde/JsonBTypesTest.java b/test-functional/src/test/java/com/arangodb/serde/JsonBTypesTest.java new file mode 100644 index 000000000..7ce63baac --- /dev/null +++ b/test-functional/src/test/java/com/arangodb/serde/JsonBTypesTest.java @@ -0,0 +1,40 @@ +package com.arangodb.serde; + +import com.arangodb.ArangoDatabase; +import com.arangodb.BaseJunit5; +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonString; +import jakarta.json.JsonValue; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; + +public class JsonBTypesTest extends BaseJunit5 { + + @BeforeAll + static void init() { + BaseJunit5.initDB(); + } + + @ParameterizedTest + @MethodSource("dbs") + void jsonNode(ArangoDatabase db) { + JsonObject doc = Json.createObjectBuilder() + .add("foo", "bar") + .build(); + JsonObject res = db.query("return @d", JsonObject.class, Collections.singletonMap("d", doc)).next(); + assertThat(res.size()).isEqualTo(1); + assertThat(res.getString("foo")).isEqualTo("bar"); + JsonValue value = db.query("return @d.foo", JsonValue.class, Collections.singletonMap("d", doc)).next(); + assertThat(value) + .isInstanceOf(JsonString.class) + .extracting(v -> ((JsonString) v).getString()) + .isEqualTo("bar"); + } + +} diff --git a/test-functional/src/test/resources/simplelogger.properties b/test-functional/src/test/resources/simplelogger.properties index 7649bd6c7..c375e20ef 100644 --- a/test-functional/src/test/resources/simplelogger.properties +++ b/test-functional/src/test/resources/simplelogger.properties @@ -9,3 +9,4 @@ org.slf4j.simpleLogger.showShortLogName=false org.slf4j.simpleLogger.defaultLogLevel=info #org.slf4j.simpleLogger.log.com.arangodb.internal.serde.JacksonUtils=debug #org.slf4j.simpleLogger.log.com.arangodb.internal.net.Communication=debug +#org.slf4j.simpleLogger.log.com.arangodb.internal.serde.InternalSerdeImpl=debug From d43344fc80d3be6c8e5c7dd1106240ebb7326644 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 9 Jan 2025 14:36:34 +0100 Subject: [PATCH 3/4] fixed enforceBytecodeVersion --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 2f105dd70..7473699b3 100644 --- a/pom.xml +++ b/pom.xml @@ -186,6 +186,7 @@ compile 1.8 + jakarta.json:jakarta.json-api jakarta.json.bind:jakarta.json.bind-api From e111e3b6a94f3edb1f57fb2a234a0be02e818651 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 9 Jan 2025 15:04:23 +0100 Subject: [PATCH 4/4] fixed shaded bundle --- pom.xml | 5 +++++ shaded/pom.xml | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/pom.xml b/pom.xml index 7473699b3..86af87cc1 100644 --- a/pom.xml +++ b/pom.xml @@ -107,6 +107,11 @@ slf4j-api 2.0.9 + + jakarta.json + jakarta.json-api + 2.1.3 + com.arangodb arangodb-java-driver diff --git a/shaded/pom.xml b/shaded/pom.xml index 5baf0197d..a8010970d 100644 --- a/shaded/pom.xml +++ b/shaded/pom.xml @@ -47,6 +47,11 @@ slf4j-api compile + + jakarta.json + jakarta.json-api + compile + com.arangodb @@ -82,6 +87,7 @@ org.slf4j:slf4j-api + jakarta.json:jakarta.json-api