From fbe888e0c72c00279e922ea4a1f9baa527ab1a14 Mon Sep 17 00:00:00 2001 From: Mathias Vandaele Date: Mon, 23 Dec 2024 13:48:42 +0100 Subject: [PATCH] refactor(document-handling): Hacking session split document modules (#3821) * refactor(document-handling): split document jackson module into a deserializer module and serializer module * refactor(document-handling): split document jackson module into a deserializer module and serializer module 2 --- .../OutboundConnectorsAutoConfiguration.java | 2 +- .../json/ConnectorsObjectMapperSupplier.java | 15 +++++-- .../connector/feel/FeelEngineWrapper.java | 5 +-- ...=> JacksonModuleDocumentDeserializer.java} | 9 ++-- .../JacksonModuleDocumentSerializer.java | 44 +++++++++++++++++++ .../serializer/DocumentSerializer.java | 7 +-- .../jackson/DocumentDeserializationTest.java | 4 +- .../jackson/DocumentSerializationTest.java | 6 ++- .../InboundConnectorContextBuilder.java | 6 +-- .../OutboundConnectorContextBuilder.java | 6 +-- 10 files changed, 75 insertions(+), 29 deletions(-) rename connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/{JacksonModuleDocument.java => JacksonModuleDocumentDeserializer.java} (95%) create mode 100644 connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocumentSerializer.java diff --git a/connector-runtime/spring-boot-starter-camunda-connectors/src/main/java/io/camunda/connector/runtime/OutboundConnectorsAutoConfiguration.java b/connector-runtime/spring-boot-starter-camunda-connectors/src/main/java/io/camunda/connector/runtime/OutboundConnectorsAutoConfiguration.java index d8e4b59a66..657891ad32 100644 --- a/connector-runtime/spring-boot-starter-camunda-connectors/src/main/java/io/camunda/connector/runtime/OutboundConnectorsAutoConfiguration.java +++ b/connector-runtime/spring-boot-starter-camunda-connectors/src/main/java/io/camunda/connector/runtime/OutboundConnectorsAutoConfiguration.java @@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.camunda.connector.api.json.ConnectorsObjectMapperSupplier; import io.camunda.connector.api.secret.SecretProvider; -import io.camunda.connector.document.annotation.jackson.JacksonModuleDocument.DocumentModuleSettings; +import io.camunda.connector.document.annotation.jackson.JacksonModuleDocumentDeserializer.DocumentModuleSettings; import io.camunda.connector.feel.FeelEngineWrapper; import io.camunda.connector.runtime.core.secret.SecretProviderAggregator; import io.camunda.connector.runtime.core.secret.SecretProviderDiscovery; diff --git a/connector-sdk/core/src/main/java/io/camunda/connector/api/json/ConnectorsObjectMapperSupplier.java b/connector-sdk/core/src/main/java/io/camunda/connector/api/json/ConnectorsObjectMapperSupplier.java index 21e0d05025..94f9796b71 100644 --- a/connector-sdk/core/src/main/java/io/camunda/connector/api/json/ConnectorsObjectMapperSupplier.java +++ b/connector-sdk/core/src/main/java/io/camunda/connector/api/json/ConnectorsObjectMapperSupplier.java @@ -23,8 +23,9 @@ import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import io.camunda.connector.document.annotation.jackson.JacksonModuleDocument; -import io.camunda.connector.document.annotation.jackson.JacksonModuleDocument.DocumentModuleSettings; +import io.camunda.connector.document.annotation.jackson.JacksonModuleDocumentDeserializer; +import io.camunda.connector.document.annotation.jackson.JacksonModuleDocumentDeserializer.DocumentModuleSettings; +import io.camunda.connector.document.annotation.jackson.JacksonModuleDocumentSerializer; import io.camunda.connector.feel.jackson.JacksonModuleFeelFunction; import io.camunda.document.factory.DocumentFactory; @@ -33,7 +34,11 @@ public class ConnectorsObjectMapperSupplier { private static final ObjectMapper DEFAULT_MAPPER = JsonMapper.builder() - .addModules(new JacksonModuleFeelFunction(), new Jdk8Module(), new JavaTimeModule()) + .addModules( + new JacksonModuleFeelFunction(), + new Jdk8Module(), + new JavaTimeModule(), + new JacksonModuleDocumentSerializer()) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS) @@ -48,6 +53,8 @@ public static ObjectMapper getCopy() { } public static ObjectMapper getCopy(DocumentFactory factory, DocumentModuleSettings settings) { - return DEFAULT_MAPPER.copy().registerModule(new JacksonModuleDocument(factory, null, settings)); + return DEFAULT_MAPPER + .copy() + .registerModule(new JacksonModuleDocumentDeserializer(factory, null, settings)); } } diff --git a/connector-sdk/feel-wrapper/src/main/java/io/camunda/connector/feel/FeelEngineWrapper.java b/connector-sdk/feel-wrapper/src/main/java/io/camunda/connector/feel/FeelEngineWrapper.java index 401cd7a2f3..6c90247379 100644 --- a/connector-sdk/feel-wrapper/src/main/java/io/camunda/connector/feel/FeelEngineWrapper.java +++ b/connector-sdk/feel-wrapper/src/main/java/io/camunda/connector/feel/FeelEngineWrapper.java @@ -27,8 +27,7 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.module.scala.DefaultScalaModule$; -import io.camunda.connector.document.annotation.jackson.JacksonModuleDocument; -import io.camunda.document.factory.DocumentFactoryImpl; +import io.camunda.connector.document.annotation.jackson.JacksonModuleDocumentSerializer; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -59,7 +58,7 @@ public FeelEngineWrapper() { .registerModule(DefaultScalaModule$.MODULE$) .registerModule(new JavaTimeModule()) .registerModule(new Jdk8Module()) - .registerModule(new JacksonModuleDocument(new DocumentFactoryImpl(null), null)) + .registerModule(new JacksonModuleDocumentSerializer()) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS); diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocument.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocumentDeserializer.java similarity index 95% rename from connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocument.java rename to connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocumentDeserializer.java index c9d40868cf..b8f0112396 100644 --- a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocument.java +++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocumentDeserializer.java @@ -30,13 +30,13 @@ import io.camunda.document.operation.DocumentOperationExecutor; import java.io.InputStream; -public class JacksonModuleDocument extends SimpleModule { +public class JacksonModuleDocumentDeserializer extends SimpleModule { private final DocumentFactory documentFactory; private final DocumentOperationExecutor operationExecutor; private final DocumentModuleSettings settings; - public JacksonModuleDocument( + public JacksonModuleDocumentDeserializer( DocumentFactory documentFactory, DocumentOperationExecutor operationExecutor, DocumentModuleSettings settings) { @@ -45,14 +45,14 @@ public JacksonModuleDocument( this.settings = settings; } - public JacksonModuleDocument( + public JacksonModuleDocumentDeserializer( DocumentFactory documentFactory, DocumentOperationExecutor operationExecutor) { this(documentFactory, operationExecutor, DocumentModuleSettings.create()); } @Override public String getModuleName() { - return "JacksonModuleDocument"; + return "JacksonModuleDocumentDeserializer"; } @Override @@ -80,7 +80,6 @@ public void setupModule(SetupContext context) { addDeserializer( String.class, new StringDocumentDeserializer(operationExecutor, documentFactory)); } - addSerializer(Document.class, new DocumentSerializer(operationExecutor)); super.setupModule(context); } diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocumentSerializer.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocumentSerializer.java new file mode 100644 index 0000000000..7cf35dbea4 --- /dev/null +++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocumentSerializer.java @@ -0,0 +1,44 @@ +/* + * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH + * under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright + * ownership. Camunda licenses this file to you under the Apache License, + * Version 2.0; you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.camunda.connector.document.annotation.jackson; + +import com.fasterxml.jackson.core.Version; +import com.fasterxml.jackson.databind.module.SimpleModule; +import io.camunda.connector.document.annotation.jackson.serializer.DocumentSerializer; +import io.camunda.document.Document; + +public class JacksonModuleDocumentSerializer extends SimpleModule { + + public JacksonModuleDocumentSerializer() {} + + @Override + public String getModuleName() { + return "JacksonModuleDocumentSerializer"; + } + + @Override + public Version version() { + // TODO: get version from pom.xml + return new Version(0, 1, 0, null, "io.camunda", "jackson-datatype-document"); + } + + @Override + public void setupModule(SetupContext context) { + addSerializer(Document.class, new DocumentSerializer()); + super.setupModule(context); + } +} diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/serializer/DocumentSerializer.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/serializer/DocumentSerializer.java index 7a47026303..f14af9aef5 100644 --- a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/serializer/DocumentSerializer.java +++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/serializer/DocumentSerializer.java @@ -22,18 +22,13 @@ import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel.CamundaDocumentMetadataModel; import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel.CamundaDocumentReferenceModel; import io.camunda.document.Document; -import io.camunda.document.operation.DocumentOperationExecutor; import io.camunda.document.reference.DocumentReference.CamundaDocumentReference; import java.io.IOException; import java.util.Optional; public class DocumentSerializer extends JsonSerializer { - private final DocumentOperationExecutor operationExecutor; - - public DocumentSerializer(DocumentOperationExecutor operationExecutor) { - this.operationExecutor = operationExecutor; - } + public DocumentSerializer() {} @Override public void serialize( diff --git a/connector-sdk/jackson-datatype-document/src/test/java/io/camunda/connector/document/jackson/DocumentDeserializationTest.java b/connector-sdk/jackson-datatype-document/src/test/java/io/camunda/connector/document/jackson/DocumentDeserializationTest.java index cc8c3b0b42..f4826f49ce 100644 --- a/connector-sdk/jackson-datatype-document/src/test/java/io/camunda/connector/document/jackson/DocumentDeserializationTest.java +++ b/connector-sdk/jackson-datatype-document/src/test/java/io/camunda/connector/document/jackson/DocumentDeserializationTest.java @@ -27,7 +27,7 @@ import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel; import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel.CamundaDocumentMetadataModel; import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel.CamundaDocumentReferenceModel; -import io.camunda.connector.document.annotation.jackson.JacksonModuleDocument; +import io.camunda.connector.document.annotation.jackson.JacksonModuleDocumentDeserializer; import io.camunda.document.Document; import io.camunda.document.factory.DocumentFactory; import io.camunda.document.operation.DocumentOperationExecutor; @@ -57,7 +57,7 @@ public class DocumentDeserializationTest { public void initialize() { objectMapper = new ObjectMapper() - .registerModule(new JacksonModuleDocument(factory, operationExecutor)) + .registerModule(new JacksonModuleDocumentDeserializer(factory, operationExecutor)) .registerModule(new Jdk8Module()); } diff --git a/connector-sdk/jackson-datatype-document/src/test/java/io/camunda/connector/document/jackson/DocumentSerializationTest.java b/connector-sdk/jackson-datatype-document/src/test/java/io/camunda/connector/document/jackson/DocumentSerializationTest.java index ce61a3121d..b14e9bb9e4 100644 --- a/connector-sdk/jackson-datatype-document/src/test/java/io/camunda/connector/document/jackson/DocumentSerializationTest.java +++ b/connector-sdk/jackson-datatype-document/src/test/java/io/camunda/connector/document/jackson/DocumentSerializationTest.java @@ -24,7 +24,8 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel.CamundaDocumentMetadataModel; import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel.CamundaDocumentReferenceModel; -import io.camunda.connector.document.annotation.jackson.JacksonModuleDocument; +import io.camunda.connector.document.annotation.jackson.JacksonModuleDocumentDeserializer; +import io.camunda.connector.document.annotation.jackson.JacksonModuleDocumentSerializer; import io.camunda.document.Document; import io.camunda.document.factory.DocumentFactory; import io.camunda.document.operation.DocumentOperationExecutor; @@ -42,7 +43,8 @@ public class DocumentSerializationTest { private final ObjectMapper objectMapper = new ObjectMapper() - .registerModule(new JacksonModuleDocument(factory, operationExecutor)) + .registerModule(new JacksonModuleDocumentDeserializer(factory, operationExecutor)) + .registerModule(new JacksonModuleDocumentSerializer()) .registerModule(new Jdk8Module()); @Test diff --git a/connector-sdk/test/src/main/java/io/camunda/connector/test/inbound/InboundConnectorContextBuilder.java b/connector-sdk/test/src/main/java/io/camunda/connector/test/inbound/InboundConnectorContextBuilder.java index 7aeef2a0b8..9a20f61e48 100644 --- a/connector-sdk/test/src/main/java/io/camunda/connector/test/inbound/InboundConnectorContextBuilder.java +++ b/connector-sdk/test/src/main/java/io/camunda/connector/test/inbound/InboundConnectorContextBuilder.java @@ -24,7 +24,7 @@ import io.camunda.connector.api.json.ConnectorsObjectMapperSupplier; import io.camunda.connector.api.secret.SecretProvider; import io.camunda.connector.api.validation.ValidationProvider; -import io.camunda.connector.document.annotation.jackson.JacksonModuleDocument; +import io.camunda.connector.document.annotation.jackson.JacksonModuleDocumentDeserializer; import io.camunda.connector.runtime.core.AbstractConnectorContext; import io.camunda.connector.runtime.core.inbound.InboundConnectorElement; import io.camunda.connector.runtime.core.inbound.InboundConnectorReportingContext; @@ -56,7 +56,7 @@ public class InboundConnectorContextBuilder { new DocumentFactoryImpl(InMemoryDocumentStore.INSTANCE); protected ObjectMapper objectMapper = ConnectorsObjectMapperSupplier.getCopy( - this.documentFactory, JacksonModuleDocument.DocumentModuleSettings.create()); + this.documentFactory, JacksonModuleDocumentDeserializer.DocumentModuleSettings.create()); public static InboundConnectorContextBuilder create() { return new InboundConnectorContextBuilder(); @@ -170,7 +170,7 @@ public InboundConnectorContextBuilder validation(ValidationProvider validationPr public InboundConnectorContextBuilder documentFactory(DocumentFactory documentFactory) { this.objectMapper = ConnectorsObjectMapperSupplier.getCopy( - documentFactory, JacksonModuleDocument.DocumentModuleSettings.create()); + documentFactory, JacksonModuleDocumentDeserializer.DocumentModuleSettings.create()); return this; } diff --git a/connector-sdk/test/src/main/java/io/camunda/connector/test/outbound/OutboundConnectorContextBuilder.java b/connector-sdk/test/src/main/java/io/camunda/connector/test/outbound/OutboundConnectorContextBuilder.java index c739b6f0ce..fb8b1813d9 100644 --- a/connector-sdk/test/src/main/java/io/camunda/connector/test/outbound/OutboundConnectorContextBuilder.java +++ b/connector-sdk/test/src/main/java/io/camunda/connector/test/outbound/OutboundConnectorContextBuilder.java @@ -24,7 +24,7 @@ import io.camunda.connector.api.outbound.OutboundConnectorContext; import io.camunda.connector.api.secret.SecretProvider; import io.camunda.connector.api.validation.ValidationProvider; -import io.camunda.connector.document.annotation.jackson.JacksonModuleDocument; +import io.camunda.connector.document.annotation.jackson.JacksonModuleDocumentDeserializer; import io.camunda.connector.runtime.core.AbstractConnectorContext; import io.camunda.connector.test.ConnectorContextTestUtil; import io.camunda.document.Document; @@ -47,7 +47,7 @@ public class OutboundConnectorContextBuilder { new DocumentFactoryImpl(InMemoryDocumentStore.INSTANCE); private ObjectMapper objectMapper = ConnectorsObjectMapperSupplier.getCopy( - this.documentFactory, JacksonModuleDocument.DocumentModuleSettings.create()); + this.documentFactory, JacksonModuleDocumentDeserializer.DocumentModuleSettings.create()); /** * @return a new instance of the {@link OutboundConnectorContextBuilder} @@ -174,7 +174,7 @@ public OutboundConnectorContextBuilder objectMapper(ObjectMapper objectMapper) { public OutboundConnectorContextBuilder documentFactory(DocumentFactory documentFactory) { this.objectMapper = ConnectorsObjectMapperSupplier.getCopy( - documentFactory, JacksonModuleDocument.DocumentModuleSettings.create()); + documentFactory, JacksonModuleDocumentDeserializer.DocumentModuleSettings.create()); return this; }