Skip to content

Commit

Permalink
refactor(document-handling): Hacking session split document modules (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
mathias-vandaele authored Dec 23, 2024
1 parent a3ada02 commit fbe888e
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Document> {

private final DocumentOperationExecutor operationExecutor;

public DocumentSerializer(DocumentOperationExecutor operationExecutor) {
this.operationExecutor = operationExecutor;
}
public DocumentSerializer() {}

@Override
public void serialize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit fbe888e

Please sign in to comment.