Note: this method doesn't perform validation or FEEl expression evaluation. Secret
* replacement is performed using the {@link io.camunda.connector.api.secret.SecretProvider}
@@ -112,4 +114,7 @@ public interface InboundConnectorContext {
* implementation requires it.
*/
void log(Activity activity);
+
+ /** Creates a new document in the Camunda Document Store. */
+ Document createDocument(DocumentCreationRequest request);
}
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 d011401861..549b873101 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,14 +23,25 @@
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.feel.jackson.JacksonModuleFeelFunction;
+import io.camunda.document.factory.DocumentFactoryImpl;
+import io.camunda.document.store.InMemoryDocumentStore;
/** Default ObjectMapper supplier to be used by the connector runtime. */
public class ConnectorsObjectMapperSupplier {
public static ObjectMapper DEFAULT_MAPPER =
JsonMapper.builder()
- .addModules(new JacksonModuleFeelFunction(), new Jdk8Module(), new JavaTimeModule())
+ .addModules(
+ new JacksonModuleFeelFunction(),
+ new JacksonModuleDocument(
+ new DocumentFactoryImpl(InMemoryDocumentStore.INSTANCE),
+ null,
+ DocumentModuleSettings.create()),
+ new Jdk8Module(),
+ new JavaTimeModule())
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
diff --git a/connector-sdk/core/src/main/java/io/camunda/connector/api/outbound/OutboundConnectorContext.java b/connector-sdk/core/src/main/java/io/camunda/connector/api/outbound/OutboundConnectorContext.java
index e0767343dc..71010c5f4a 100644
--- a/connector-sdk/core/src/main/java/io/camunda/connector/api/outbound/OutboundConnectorContext.java
+++ b/connector-sdk/core/src/main/java/io/camunda/connector/api/outbound/OutboundConnectorContext.java
@@ -16,17 +16,16 @@
*/
package io.camunda.connector.api.outbound;
+import io.camunda.document.Document;
+import io.camunda.document.store.DocumentCreationRequest;
+
/**
* The context object provided to a connector function. The context allows to fetch information
* injected by the environment runtime.
*/
public interface OutboundConnectorContext {
- /**
- * Context information about the activated job.
- *
- * @return
- */
+ /** Context information about the activated job. */
JobContext getJobContext();
/**
@@ -47,4 +46,7 @@ public interface OutboundConnectorContext {
* @return deserialized and validated variables with secrets replaced
*/
T bindVariables(Class cls);
+
+ /** Creates a new document in the Camunda Document Store. */
+ Document createDocument(DocumentCreationRequest request);
}
diff --git a/connector-sdk/document/pom.xml b/connector-sdk/document/pom.xml
new file mode 100644
index 0000000000..d9dfa8869f
--- /dev/null
+++ b/connector-sdk/document/pom.xml
@@ -0,0 +1,19 @@
+
+ 4.0.0
+
+
+ io.camunda.connector
+ connector-sdk-parent
+ ../pom.xml
+ 8.6.0-SNAPSHOT
+
+
+ connector-document
+ Camunda Connector Document
+ connector-document
+ jar
+
+
+
+
\ No newline at end of file
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/CamundaDocument.java b/connector-sdk/document/src/main/java/io/camunda/document/CamundaDocument.java
new file mode 100644
index 0000000000..a513178d03
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/CamundaDocument.java
@@ -0,0 +1,68 @@
+/*
+ * 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.document;
+
+import io.camunda.document.reference.DocumentReference;
+import io.camunda.document.reference.DocumentReference.CamundaDocumentReference;
+import io.camunda.document.store.CamundaDocumentStore;
+import java.io.InputStream;
+import java.util.Base64;
+
+public class CamundaDocument implements Document {
+
+ private final DocumentMetadata metadata;
+ private final CamundaDocumentReference reference;
+ private final CamundaDocumentStore documentStore;
+
+ public CamundaDocument(
+ DocumentMetadata metadata,
+ CamundaDocumentReference reference,
+ CamundaDocumentStore documentStore) {
+ this.metadata = metadata;
+ this.reference = reference;
+ this.documentStore = documentStore;
+ }
+
+ @Override
+ public DocumentMetadata metadata() {
+ return metadata;
+ }
+
+ @Override
+ public String asBase64() {
+ return Base64.getEncoder().encodeToString(asByteArray());
+ }
+
+ @Override
+ public InputStream asInputStream() {
+ return documentStore.getDocumentContent(reference);
+ }
+
+ @Override
+ public byte[] asByteArray() {
+ try {
+ return documentStore.getDocumentContent(reference).readAllBytes();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to read document content", e);
+ }
+ }
+
+ @Override
+ public DocumentReference reference() {
+ return reference;
+ }
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/Document.java b/connector-sdk/document/src/main/java/io/camunda/document/Document.java
new file mode 100644
index 0000000000..28df9738ae
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/Document.java
@@ -0,0 +1,41 @@
+/*
+ * 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.document;
+
+import io.camunda.document.reference.DocumentReference;
+import java.io.InputStream;
+
+/**
+ * Represents a uniform document (file) object that can be passed between connectors and used in the
+ * FEEL engine.
+ */
+public interface Document {
+
+ /**
+ * Domain-specific metadata that can be attached to the document. When a file is consumed by a
+ * connector as input, the metadata originates from the
+ */
+ DocumentMetadata metadata();
+
+ String asBase64();
+
+ InputStream asInputStream();
+
+ byte[] asByteArray();
+
+ DocumentReference reference();
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/DocumentMetadata.java b/connector-sdk/document/src/main/java/io/camunda/document/DocumentMetadata.java
new file mode 100644
index 0000000000..8d67bb1683
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/DocumentMetadata.java
@@ -0,0 +1,52 @@
+/*
+ * 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.document;
+
+import java.util.Map;
+
+public class DocumentMetadata {
+
+ public static final String CONTENT_TYPE = "contentType";
+ public static final String FILE_NAME = "fileName";
+ public static final String DESCRIPTION = "description";
+
+ private final Map keys;
+
+ public DocumentMetadata(Map keys) {
+ this.keys = keys;
+ }
+
+ public Map getKeys() {
+ return keys;
+ }
+
+ public Object getKey(String key) {
+ return keys.get(key);
+ }
+
+ public String getContentType() {
+ return (String) keys.get(CONTENT_TYPE);
+ }
+
+ public String getFileName() {
+ return (String) keys.get(FILE_NAME);
+ }
+
+ public String getDescription() {
+ return (String) keys.get(DESCRIPTION);
+ }
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/factory/DocumentFactory.java b/connector-sdk/document/src/main/java/io/camunda/document/factory/DocumentFactory.java
new file mode 100644
index 0000000000..3462559a28
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/factory/DocumentFactory.java
@@ -0,0 +1,33 @@
+/*
+ * 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.document.factory;
+
+import io.camunda.document.Document;
+import io.camunda.document.reference.DocumentReference;
+import io.camunda.document.store.DocumentCreationRequest;
+
+public interface DocumentFactory {
+
+ /** Given a document reference, create the Document object */
+ Document resolve(DocumentReference reference);
+
+ /**
+ * Upload a document to the underlying document store and parse the document reference into a
+ * Document object
+ */
+ Document create(DocumentCreationRequest request);
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/factory/DocumentFactoryImpl.java b/connector-sdk/document/src/main/java/io/camunda/document/factory/DocumentFactoryImpl.java
new file mode 100644
index 0000000000..21dc9237e5
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/factory/DocumentFactoryImpl.java
@@ -0,0 +1,56 @@
+/*
+ * 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.document.factory;
+
+import io.camunda.document.CamundaDocument;
+import io.camunda.document.Document;
+import io.camunda.document.reference.DocumentReference;
+import io.camunda.document.reference.DocumentReference.CamundaDocumentReference;
+import io.camunda.document.reference.DocumentReference.ExternalDocumentReference;
+import io.camunda.document.store.CamundaDocumentStore;
+import io.camunda.document.store.DocumentCreationRequest;
+
+public class DocumentFactoryImpl implements DocumentFactory {
+
+ private final CamundaDocumentStore documentStore;
+
+ public DocumentFactoryImpl(CamundaDocumentStore documentStore) {
+ this.documentStore = documentStore;
+ }
+
+ @Override
+ public Document resolve(DocumentReference reference) {
+ if (reference == null) {
+ return null;
+ }
+ if (reference instanceof CamundaDocumentReference camundaDocumentReference) {
+ return new CamundaDocument(
+ camundaDocumentReference.metadata(), camundaDocumentReference, documentStore);
+ }
+ if (reference instanceof ExternalDocumentReference ignored) {
+ throw new IllegalArgumentException(
+ "External document references are not yet supported: " + reference.getClass());
+ }
+ throw new IllegalArgumentException("Unknown document reference type: " + reference.getClass());
+ }
+
+ @Override
+ public Document create(DocumentCreationRequest request) {
+ var reference = documentStore.createDocument(request);
+ return resolve(reference);
+ }
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/operation/AggregatingOperationExecutor.java b/connector-sdk/document/src/main/java/io/camunda/document/operation/AggregatingOperationExecutor.java
new file mode 100644
index 0000000000..9847f506c2
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/operation/AggregatingOperationExecutor.java
@@ -0,0 +1,34 @@
+/*
+ * 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.document.operation;
+
+import io.camunda.document.Document;
+
+public class AggregatingOperationExecutor implements DocumentOperationExecutor {
+
+ public AggregatingOperationExecutor() {}
+
+ @Override
+ public boolean matches(DocumentOperation operationReference) {
+ return true;
+ }
+
+ @Override
+ public Object execute(DocumentOperation operationReference, Document document) {
+ return null;
+ }
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/operation/Base64OperationExecutor.java b/connector-sdk/document/src/main/java/io/camunda/document/operation/Base64OperationExecutor.java
new file mode 100644
index 0000000000..31c18d4d9d
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/operation/Base64OperationExecutor.java
@@ -0,0 +1,32 @@
+/*
+ * 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.document.operation;
+
+import io.camunda.document.Document;
+
+public class Base64OperationExecutor implements DocumentOperationExecutor {
+
+ @Override
+ public boolean matches(DocumentOperation operationReference) {
+ return "base64".equalsIgnoreCase(operationReference.name());
+ }
+
+ @Override
+ public Object execute(DocumentOperation operationReference, Document document) {
+ return document.asBase64();
+ }
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/operation/DocumentOperation.java b/connector-sdk/document/src/main/java/io/camunda/document/operation/DocumentOperation.java
new file mode 100644
index 0000000000..24bf3c064f
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/operation/DocumentOperation.java
@@ -0,0 +1,21 @@
+/*
+ * 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.document.operation;
+
+import java.util.Map;
+
+public record DocumentOperation(String name, Map params) {}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/operation/DocumentOperationExecutor.java b/connector-sdk/document/src/main/java/io/camunda/document/operation/DocumentOperationExecutor.java
new file mode 100644
index 0000000000..b07323654d
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/operation/DocumentOperationExecutor.java
@@ -0,0 +1,26 @@
+/*
+ * 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.document.operation;
+
+import io.camunda.document.Document;
+
+public interface DocumentOperationExecutor {
+
+ boolean matches(DocumentOperation operationReference);
+
+ Object execute(DocumentOperation operationReference, Document document);
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/reference/CamundaDocumentReferenceImpl.java b/connector-sdk/document/src/main/java/io/camunda/document/reference/CamundaDocumentReferenceImpl.java
new file mode 100644
index 0000000000..439945acf6
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/reference/CamundaDocumentReferenceImpl.java
@@ -0,0 +1,23 @@
+/*
+ * 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.document.reference;
+
+import io.camunda.document.DocumentMetadata;
+
+public record CamundaDocumentReferenceImpl(
+ String storeId, String documentId, DocumentMetadata metadata)
+ implements DocumentReference.CamundaDocumentReference {}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/reference/DocumentReference.java b/connector-sdk/document/src/main/java/io/camunda/document/reference/DocumentReference.java
new file mode 100644
index 0000000000..3c384ff698
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/reference/DocumentReference.java
@@ -0,0 +1,34 @@
+/*
+ * 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.document.reference;
+
+import io.camunda.document.DocumentMetadata;
+
+public interface DocumentReference {
+
+ interface CamundaDocumentReference extends DocumentReference {
+ String storeId();
+
+ String documentId();
+
+ DocumentMetadata metadata();
+ }
+
+ interface ExternalDocumentReference extends DocumentReference {
+ String url();
+ }
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/store/CamundaDocumentStore.java b/connector-sdk/document/src/main/java/io/camunda/document/store/CamundaDocumentStore.java
new file mode 100644
index 0000000000..ab36db890a
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/store/CamundaDocumentStore.java
@@ -0,0 +1,29 @@
+/*
+ * 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.document.store;
+
+import io.camunda.document.reference.DocumentReference.CamundaDocumentReference;
+import java.io.InputStream;
+
+public interface CamundaDocumentStore {
+
+ CamundaDocumentReference createDocument(DocumentCreationRequest request);
+
+ InputStream getDocumentContent(CamundaDocumentReference reference);
+
+ void deleteDocument(CamundaDocumentReference reference);
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/store/DocumentCreationRequest.java b/connector-sdk/document/src/main/java/io/camunda/document/store/DocumentCreationRequest.java
new file mode 100644
index 0000000000..a2109cf500
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/store/DocumentCreationRequest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.document.store;
+
+import io.camunda.document.DocumentMetadata;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Map;
+
+public record DocumentCreationRequest(
+ DocumentMetadata metadata, InputStream content, String documentId, String storeId) {
+
+ public static BuilderStepMetadata from(InputStream content) {
+ return new BuilderStepMetadata(content);
+ }
+
+ public static BuilderStepMetadata from(byte[] content) {
+ return new BuilderStepMetadata(new ByteArrayInputStream(content));
+ }
+
+ public static class BuilderStepMetadata {
+ private final InputStream content;
+
+ public BuilderStepMetadata(InputStream content) {
+ this.content = content;
+ }
+
+ public BuilderFinalStep metadata(DocumentMetadata metadata) {
+ return new BuilderFinalStep(metadata, content);
+ }
+
+ public BuilderFinalStep metadata(Map metadata) {
+ return new BuilderFinalStep(new DocumentMetadata(metadata), content);
+ }
+ }
+
+ public static class BuilderFinalStep {
+ private final DocumentMetadata metadata;
+ private final InputStream content;
+ private String documentId;
+ private String storeId;
+
+ public BuilderFinalStep(DocumentMetadata metadata, InputStream content) {
+ this.metadata = metadata;
+ this.content = content;
+ }
+
+ public BuilderFinalStep documentId(String documentId) {
+ this.documentId = documentId;
+ return this;
+ }
+
+ public BuilderFinalStep storeId(String storeId) {
+ this.storeId = storeId;
+ return this;
+ }
+
+ public DocumentCreationRequest build() {
+ return new DocumentCreationRequest(metadata, content, documentId, storeId);
+ }
+ }
+}
diff --git a/connector-sdk/document/src/main/java/io/camunda/document/store/InMemoryDocumentStore.java b/connector-sdk/document/src/main/java/io/camunda/document/store/InMemoryDocumentStore.java
new file mode 100644
index 0000000000..d0b48f8a01
--- /dev/null
+++ b/connector-sdk/document/src/main/java/io/camunda/document/store/InMemoryDocumentStore.java
@@ -0,0 +1,71 @@
+/*
+ * 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.document.store;
+
+import io.camunda.document.DocumentMetadata;
+import io.camunda.document.reference.CamundaDocumentReferenceImpl;
+import io.camunda.document.reference.DocumentReference.CamundaDocumentReference;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/** Use this document store to store documents in memory. This is useful for testing purposes. */
+public class InMemoryDocumentStore implements CamundaDocumentStore {
+
+ public static final String STORE_ID = "in-memory";
+
+ public static InMemoryDocumentStore INSTANCE = new InMemoryDocumentStore();
+
+ private final Map documents = new HashMap<>();
+
+ private InMemoryDocumentStore() {}
+
+ @Override
+ public CamundaDocumentReference createDocument(DocumentCreationRequest request) {
+ final String id =
+ request.documentId() != null ? request.documentId() : UUID.randomUUID().toString();
+ final DocumentMetadata metadata = request.metadata();
+ final byte[] content;
+ try (InputStream contentStream = request.content()) {
+ content = contentStream.readAllBytes();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to read document content", e);
+ }
+ documents.put(id, content);
+ return new CamundaDocumentReferenceImpl(STORE_ID, id, metadata);
+ }
+
+ @Override
+ public InputStream getDocumentContent(CamundaDocumentReference reference) {
+ var content = documents.get(reference.documentId());
+ if (content == null) {
+ throw new RuntimeException("Document not found: " + reference.documentId());
+ }
+ return new ByteArrayInputStream(content);
+ }
+
+ @Override
+ public void deleteDocument(CamundaDocumentReference reference) {
+ documents.remove(reference.documentId());
+ }
+
+ public void clear() {
+ documents.clear();
+ }
+}
diff --git a/connector-sdk/jackson-datatype-document/pom.xml b/connector-sdk/jackson-datatype-document/pom.xml
new file mode 100644
index 0000000000..86d91be000
--- /dev/null
+++ b/connector-sdk/jackson-datatype-document/pom.xml
@@ -0,0 +1,55 @@
+
+ 4.0.0
+
+
+ io.camunda.connector
+ connector-sdk-parent
+ ../pom.xml
+ 8.6.0-SNAPSHOT
+
+
+ jackson-datatype-document
+ Jackson module to handle Connector SDK file objects
+
+
+
+ io.camunda.connector
+ connector-document
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ test
+
+
+ org.assertj
+ assertj-core
+ test
+
+
+ org.mockito
+ mockito-core
+ test
+
+
+ org.mockito
+ mockito-junit-jupiter
+ test
+
+
+ org.skyscreamer
+ jsonassert
+ test
+
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-jdk8
+ test
+
+
+
diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/DocumentOperationResult.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/DocumentOperationResult.java
new file mode 100644
index 0000000000..16bc3f3997
--- /dev/null
+++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/DocumentOperationResult.java
@@ -0,0 +1,21 @@
+/*
+ * 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 java.util.function.Supplier;
+
+public interface DocumentOperationResult extends Supplier {}
diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/DocumentReferenceModel.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/DocumentReferenceModel.java
new file mode 100644
index 0000000000..8a211ec51b
--- /dev/null
+++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/DocumentReferenceModel.java
@@ -0,0 +1,84 @@
+/*
+ * 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.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonSubTypes;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
+import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel.CamundaDocumentReferenceModel;
+import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel.ExternalDocumentReferenceModel;
+import io.camunda.document.DocumentMetadata;
+import io.camunda.document.operation.DocumentOperation;
+import io.camunda.document.reference.DocumentReference;
+import java.util.Map;
+import java.util.Optional;
+
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ property = DocumentReferenceModel.DISCRIMINATOR_KEY,
+ visible = true,
+ include = As.EXISTING_PROPERTY)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = CamundaDocumentReferenceModel.class, name = "camunda"),
+ @JsonSubTypes.Type(value = ExternalDocumentReferenceModel.class, name = "external")
+})
+@JsonIgnoreProperties(ignoreUnknown = true)
+public sealed interface DocumentReferenceModel extends DocumentReference {
+
+ String DISCRIMINATOR_KEY = "documentType";
+
+ /**
+ * Document references may have operations associated with them. Operation indicates that the
+ * document should not be used as is, but should be transformed or processed in some way. This
+ * processing must take place in the context of the connector.
+ */
+ @JsonInclude(Include.NON_EMPTY)
+ Optional operation();
+
+ record CamundaDocumentReferenceModel(
+ String storeId,
+ String documentId,
+ @JsonProperty("metadata") Map rawMetadata,
+ Optional operation)
+ implements DocumentReferenceModel, CamundaDocumentReference {
+
+ @JsonProperty(DISCRIMINATOR_KEY)
+ private String documentType() {
+ return "camunda";
+ }
+
+ @Override
+ @JsonIgnore
+ public DocumentMetadata metadata() {
+ return new DocumentMetadata(rawMetadata);
+ }
+ }
+
+ record ExternalDocumentReferenceModel(String url, Optional operation)
+ implements DocumentReferenceModel, ExternalDocumentReference {
+
+ @JsonProperty(DISCRIMINATOR_KEY)
+ private String documentType() {
+ return "external";
+ }
+ }
+}
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/JacksonModuleDocument.java
new file mode 100644
index 0000000000..c9d40868cf
--- /dev/null
+++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/JacksonModuleDocument.java
@@ -0,0 +1,126 @@
+/*
+ * 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.deserializer.ByteArrayDocumentDeserializer;
+import io.camunda.connector.document.annotation.jackson.deserializer.DocumentDeserializer;
+import io.camunda.connector.document.annotation.jackson.deserializer.DocumentOperationResultDeserializer;
+import io.camunda.connector.document.annotation.jackson.deserializer.InputStreamDocumentDeserializer;
+import io.camunda.connector.document.annotation.jackson.deserializer.ObjectDocumentDeserializer;
+import io.camunda.connector.document.annotation.jackson.deserializer.StringDocumentDeserializer;
+import io.camunda.connector.document.annotation.jackson.serializer.DocumentSerializer;
+import io.camunda.document.Document;
+import io.camunda.document.factory.DocumentFactory;
+import io.camunda.document.operation.DocumentOperationExecutor;
+import java.io.InputStream;
+
+public class JacksonModuleDocument extends SimpleModule {
+
+ private final DocumentFactory documentFactory;
+ private final DocumentOperationExecutor operationExecutor;
+ private final DocumentModuleSettings settings;
+
+ public JacksonModuleDocument(
+ DocumentFactory documentFactory,
+ DocumentOperationExecutor operationExecutor,
+ DocumentModuleSettings settings) {
+ this.documentFactory = documentFactory;
+ this.operationExecutor = operationExecutor;
+ this.settings = settings;
+ }
+
+ public JacksonModuleDocument(
+ DocumentFactory documentFactory, DocumentOperationExecutor operationExecutor) {
+ this(documentFactory, operationExecutor, DocumentModuleSettings.create());
+ }
+
+ @Override
+ public String getModuleName() {
+ return "JacksonModuleDocument";
+ }
+
+ @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) {
+ addDeserializer(Document.class, new DocumentDeserializer(operationExecutor, documentFactory));
+ addDeserializer(
+ DocumentOperationResult.class,
+ new DocumentOperationResultDeserializer(operationExecutor, documentFactory));
+ addDeserializer(
+ byte[].class, new ByteArrayDocumentDeserializer(operationExecutor, documentFactory));
+ addDeserializer(
+ InputStream.class, new InputStreamDocumentDeserializer(operationExecutor, documentFactory));
+ if (settings.enableObject) {
+ addDeserializer(
+ Object.class,
+ new ObjectDocumentDeserializer(operationExecutor, documentFactory, settings.lazy));
+ }
+ if (settings.enableString) {
+ addDeserializer(
+ String.class, new StringDocumentDeserializer(operationExecutor, documentFactory));
+ }
+ addSerializer(Document.class, new DocumentSerializer(operationExecutor));
+ super.setupModule(context);
+ }
+
+ public static class DocumentModuleSettings {
+
+ private boolean lazy = true;
+ private boolean enableObject = true;
+ private boolean enableString = true;
+
+ private DocumentModuleSettings() {}
+
+ public static DocumentModuleSettings create() {
+ return new DocumentModuleSettings();
+ }
+
+ /**
+ * Enable lazy operations for document deserialization.
+ *
+ *
When enabled, given that the connector consumes a document as a generic {@link Object}
+ * type, and an operation is present in the document reference, the operation is not executed in
+ * the deserialization phase. Instead, the operation is executed during serialization using the
+ * {@link DocumentSerializer}.
+ *
+ *
Disable lazy operations if your connector doesn't use the document module for
+ * serialization (or doesn't use Jackson at all).
+ *
+ *
This takes no effect if {@link #enableObject(boolean)} is disabled.
+ */
+ public void lazyOperations(boolean lazy) {
+ this.lazy = lazy;
+ }
+
+ /** Enable deserialization of document references into objects. */
+ public void enableObject(boolean enable) {
+ this.enableObject = enable;
+ }
+
+ /** Enable deserialization of document references into strings. */
+ public void enableString(boolean enable) {
+ this.enableString = enable;
+ }
+ }
+}
diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/ByteArrayDocumentDeserializer.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/ByteArrayDocumentDeserializer.java
new file mode 100644
index 0000000000..06451acf6a
--- /dev/null
+++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/ByteArrayDocumentDeserializer.java
@@ -0,0 +1,53 @@
+/*
+ * 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.deserializer;
+
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.deser.std.PrimitiveArrayDeserializers;
+import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel;
+import io.camunda.document.factory.DocumentFactory;
+import io.camunda.document.operation.DocumentOperationExecutor;
+import java.io.IOException;
+
+public class ByteArrayDocumentDeserializer extends DocumentDeserializerBase {
+
+ private final JsonDeserializer> fallbackDeserializer =
+ PrimitiveArrayDeserializers.forType(byte.class);
+
+ public ByteArrayDocumentDeserializer(
+ DocumentOperationExecutor operationExecutor, DocumentFactory documentFactory) {
+ super(operationExecutor, documentFactory);
+ }
+
+ @Override
+ public byte[] deserializeDocumentReference(
+ DocumentReferenceModel reference, DeserializationContext ctx) {
+
+ ensureNoOperation(reference);
+ var document = createDocument(reference);
+ return document.asByteArray();
+ }
+
+ @Override
+ public byte[] fallback(JsonNode node, DeserializationContext ctx) throws IOException {
+ var parser = node.traverse(ctx.getParser().getCodec());
+ parser.nextToken();
+ return (byte[]) fallbackDeserializer.deserialize(parser, ctx);
+ }
+}
diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/DocumentDeserializer.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/DocumentDeserializer.java
new file mode 100644
index 0000000000..94e4302909
--- /dev/null
+++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/DocumentDeserializer.java
@@ -0,0 +1,50 @@
+/*
+ * 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.deserializer;
+
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonNode;
+import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel;
+import io.camunda.document.Document;
+import io.camunda.document.factory.DocumentFactory;
+import io.camunda.document.operation.DocumentOperationExecutor;
+import java.io.IOException;
+
+public class DocumentDeserializer extends DocumentDeserializerBase {
+
+ public DocumentDeserializer(
+ DocumentOperationExecutor operationExecutor, DocumentFactory documentFactory) {
+ super(operationExecutor, documentFactory);
+ }
+
+ @Override
+ public Document deserializeDocumentReference(
+ DocumentReferenceModel reference, DeserializationContext ctx) {
+
+ ensureNoOperation(reference);
+ return createDocument(reference);
+ }
+
+ @Override
+ public Document fallback(JsonNode node, DeserializationContext ctx) throws IOException {
+ var fieldName = ctx.getParser().currentName();
+ throw new IllegalArgumentException(
+ fieldName
+ + ": unsupported document format. Expected a document reference, got: "
+ + fieldName);
+ }
+}
diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/DocumentDeserializerBase.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/DocumentDeserializerBase.java
new file mode 100644
index 0000000000..9bff270900
--- /dev/null
+++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/DocumentDeserializerBase.java
@@ -0,0 +1,96 @@
+/*
+ * 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.deserializer;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import io.camunda.connector.document.annotation.jackson.DocumentOperationResult;
+import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel;
+import io.camunda.document.Document;
+import io.camunda.document.factory.DocumentFactory;
+import io.camunda.document.operation.DocumentOperation;
+import io.camunda.document.operation.DocumentOperationExecutor;
+import java.io.IOException;
+
+public abstract class DocumentDeserializerBase extends JsonDeserializer {
+
+ protected final DocumentOperationExecutor operationExecutor;
+ protected final DocumentFactory documentFactory;
+
+ public DocumentDeserializerBase(
+ DocumentOperationExecutor operationExecutor, DocumentFactory documentFactory) {
+ this.operationExecutor = operationExecutor;
+ this.documentFactory = documentFactory;
+ }
+
+ @Override
+ public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
+
+ JsonNode node = p.readValueAsTree();
+ if (node == null || node.isNull()) {
+ return null;
+ }
+ if (isDocumentReference(node)) {
+ var reference = toReference(node, ctxt);
+ return deserializeDocumentReference(reference, ctxt);
+ }
+ return fallback(node, ctxt);
+ }
+
+ /** Will be invoked when the deserializable data is a document reference. */
+ public abstract T deserializeDocumentReference(
+ DocumentReferenceModel reference, DeserializationContext ctx) throws IOException;
+
+ /**
+ * Will be invoked when the deserializable data is not a document reference. Deserializers should
+ * implement this method to provide a fallback behavior.
+ */
+ public abstract T fallback(JsonNode node, DeserializationContext ctx) throws IOException;
+
+ protected boolean isDocumentReference(JsonNode node) {
+ return node.has(DocumentReferenceModel.DISCRIMINATOR_KEY);
+ }
+
+ protected DocumentReferenceModel toReference(JsonNode node, DeserializationContext ctx)
+ throws IOException {
+
+ if (!isDocumentReference(node)) {
+ throw new IllegalArgumentException(
+ "Unsupported document format. Expected a document reference, got: " + node);
+ }
+ return ctx.readTreeAsValue(node, DocumentReferenceModel.class);
+ }
+
+ protected void ensureNoOperation(DocumentReferenceModel reference) {
+ if (reference.operation().isPresent()) {
+ throw new IllegalArgumentException(
+ "Unsupported document format. Expected a document reference without operation, got: "
+ + reference);
+ }
+ }
+
+ protected Document createDocument(DocumentReferenceModel reference) {
+ return documentFactory.resolve(reference);
+ }
+
+ protected DocumentOperationResult> deserializeOperation(
+ DocumentReferenceModel reference, DocumentOperation operation) {
+ return () -> operationExecutor.execute(operation, createDocument(reference));
+ }
+}
diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/DocumentOperationResultDeserializer.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/DocumentOperationResultDeserializer.java
new file mode 100644
index 0000000000..13f3bd105f
--- /dev/null
+++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/DocumentOperationResultDeserializer.java
@@ -0,0 +1,91 @@
+/*
+ * 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.deserializer;
+
+import com.fasterxml.jackson.databind.BeanProperty;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
+import io.camunda.connector.document.annotation.jackson.DocumentOperationResult;
+import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel;
+import io.camunda.document.factory.DocumentFactory;
+import io.camunda.document.operation.DocumentOperationExecutor;
+
+public class DocumentOperationResultDeserializer
+ extends DocumentDeserializerBase> implements ContextualDeserializer {
+
+ private final JavaType valueType;
+
+ public DocumentOperationResultDeserializer(
+ DocumentOperationExecutor operationExecutor, DocumentFactory documentFactory) {
+ super(operationExecutor, documentFactory);
+ this.valueType = null;
+ }
+
+ public DocumentOperationResultDeserializer(
+ DocumentOperationExecutor operationExecutor,
+ DocumentFactory documentFactory,
+ JavaType valueType) {
+ super(operationExecutor, documentFactory);
+ this.valueType = valueType;
+ }
+
+ @Override
+ public DocumentOperationResult> deserializeDocumentReference(
+ DocumentReferenceModel reference, DeserializationContext ctx) {
+ var operation =
+ reference
+ .operation()
+ .orElseThrow(
+ () -> new IllegalArgumentException("Document reference must contain an operation"));
+ var resultSupplier = deserializeOperation(reference, operation);
+
+ return () -> {
+ var result = resultSupplier.get();
+ if (valueType == null) {
+ return result;
+ }
+ if (valueType.getContentType().isTypeOrSubTypeOf(result.getClass())) {
+ return result;
+ } else {
+ throw new IllegalArgumentException(
+ "Unexpected operation result type: "
+ + result.getClass()
+ + " while executing operation "
+ + operation.name()
+ + ". Expected "
+ + valueType.getContentType()
+ + ", but got "
+ + result.getClass());
+ }
+ };
+ }
+
+ @Override
+ public DocumentOperationResult> fallback(JsonNode node, DeserializationContext ctx) {
+ throw new IllegalArgumentException(
+ "Unsupported document format. Expected a document reference, got: " + node);
+ }
+
+ @Override
+ public JsonDeserializer> createContextual(DeserializationContext ctxt, BeanProperty property) {
+ var valueType = property.getType();
+ return new DocumentOperationResultDeserializer(operationExecutor, documentFactory, valueType);
+ }
+}
diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/InputStreamDocumentDeserializer.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/InputStreamDocumentDeserializer.java
new file mode 100644
index 0000000000..e339f1d057
--- /dev/null
+++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/InputStreamDocumentDeserializer.java
@@ -0,0 +1,46 @@
+/*
+ * 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.deserializer;
+
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonNode;
+import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel;
+import io.camunda.document.factory.DocumentFactory;
+import io.camunda.document.operation.DocumentOperationExecutor;
+import java.io.InputStream;
+
+public class InputStreamDocumentDeserializer extends DocumentDeserializerBase {
+
+ public InputStreamDocumentDeserializer(
+ DocumentOperationExecutor operationExecutor, DocumentFactory documentFactory) {
+ super(operationExecutor, documentFactory);
+ }
+
+ @Override
+ public InputStream deserializeDocumentReference(
+ DocumentReferenceModel reference, DeserializationContext ctx) {
+ ensureNoOperation(reference);
+ var document = createDocument(reference);
+ return document.asInputStream();
+ }
+
+ @Override
+ public InputStream fallback(JsonNode node, DeserializationContext ctx) {
+ throw new IllegalArgumentException(
+ "unsupported document format. Expected a document reference, got: " + node);
+ }
+}
diff --git a/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/ObjectDocumentDeserializer.java b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/ObjectDocumentDeserializer.java
new file mode 100644
index 0000000000..9a8712f85c
--- /dev/null
+++ b/connector-sdk/jackson-datatype-document/src/main/java/io/camunda/connector/document/annotation/jackson/deserializer/ObjectDocumentDeserializer.java
@@ -0,0 +1,87 @@
+/*
+ * 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.deserializer;
+
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer;
+import io.camunda.connector.document.annotation.jackson.DocumentReferenceModel;
+import io.camunda.document.factory.DocumentFactory;
+import io.camunda.document.operation.DocumentOperationExecutor;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+
+public class ObjectDocumentDeserializer extends DocumentDeserializerBase