Repository: holunda-io/camunda-bpm-taskpool
Issue: Consistent usage of configured objectmapper

### Steps to reproduce

* camunda-bpm-taskpool version: 2.1.3
* Camunda BPM version: any
* JDK version:  11
* Operating system: any
* Steps: If the complex payload of tasks is being serialized, taskpool collector uses a default kotlin jackon objectmapper instead of configured one.

### Expected behaviour

The configured jackson object mapper is used.

### Actual behaviour

The default jackson kotlin object mapper is used.




Changed files:
engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/sender/accumulator/projectProperties.kt
engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/sender/accumulator/ProjectingCommandAccumulator.kt
engine/taskpool-collector/src/test/kotlin/io/holunda/camunda/taskpool/sender/projectPropertiesTest.kt

diff --git a/engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/sender/accumulator/ProjectingCommandAccumulator.kt b/engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/sender/accumulator/ProjectingCommandAccumulator.kt
index cda5deb10..5a062b84c 100644
--- a/engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/sender/accumulator/ProjectingCommandAccumulator.kt
+++ b/engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/sender/accumulator/ProjectingCommandAccumulator.kt
@@ -1,15 +1,17 @@
 package io.holunda.camunda.taskpool.sender.accumulator
 
 import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
 import io.holunda.camunda.taskpool.api.business.WithCorrelations
 import io.holunda.camunda.taskpool.api.task.*
+import io.holunda.camunda.taskpool.configureTaskpoolJacksonObjectMapper
 import io.holunda.camunda.variable.serializer.serialize
 import kotlin.reflect.KClass
 
 
 /**
  * Sorts commands by their order id and project attribute to one command
- * @param objectMapper optional object mapper used for serialization, defaults to jacksonObjectMapper with Kotlin module.
+ * @param objectMapper optional object mapper used for serialization.
  */
 class ProjectingCommandAccumulator(
   val objectMapper: ObjectMapper
@@ -74,7 +76,9 @@ class ProjectingCommandAccumulator(
       WithPayload::payload.name,
       WithCorrelations::correlations.name
     ),
-    projectionErrorDetector = EngineTaskCommandProjectionErrorDetector
+    projectionErrorDetector = EngineTaskCommandProjectionErrorDetector,
+    mapper = jacksonMapper(objectMapper = objectMapper),
+    unmapper = jacksonUnmapper(clazz = command::class.java, objectMapper = objectMapper)
   )
 
   /**
diff --git a/engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/sender/accumulator/projectProperties.kt b/engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/sender/accumulator/projectProperties.kt
index 78f5ab626..a397d8771 100644
--- a/engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/sender/accumulator/projectProperties.kt
+++ b/engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/sender/accumulator/projectProperties.kt
@@ -1,6 +1,7 @@
 package io.holunda.camunda.taskpool.sender.accumulator
 
 import com.fasterxml.jackson.core.type.TypeReference
+import com.fasterxml.jackson.databind.ObjectMapper
 import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
 import io.holunda.camunda.taskpool.configureTaskpoolJacksonObjectMapper
 import org.slf4j.LoggerFactory
@@ -38,8 +39,8 @@ fun <T : Any> projectProperties(
   original: T,
   details: List<Any> = emptyList(),
   propertyOperationConfig: PropertyOperationConfiguration = mapOf(),
-  mapper: Mapper<T> = jacksonMapper(),
-  unmapper: Unmapper<T> = jacksonUnmapper(original::class.java),
+  mapper: Mapper<T>,
+  unmapper: Unmapper<T>,
   ignoredProperties: List<String> = emptyList(),
   projectionErrorDetector: ProjectionErrorDetector
 ): T {
@@ -100,8 +101,8 @@ fun <T : Any> projectProperties(
 /**
  * Default Jackson Mapper (object to map).
  */
-fun <T> jacksonMapper(): Mapper<T> = {
-  jacksonObjectMapper()
+fun <T> jacksonMapper(objectMapper: ObjectMapper = jacksonObjectMapper()): Mapper<T> = {
+  objectMapper
     .configureTaskpoolJacksonObjectMapper()
     .convertValue(it, object : TypeReference<MutableMap<String, Any?>>() {})
 }
@@ -109,9 +110,10 @@ fun <T> jacksonMapper(): Mapper<T> = {
 /**
  * Default Jackson Unmapper (map to object).
  */
-fun <T> jacksonUnmapper(clazz: Class<T>): Unmapper<T> = {
-  jacksonObjectMapper()
-    .configureTaskpoolJacksonObjectMapper().convertValue(it, clazz)
+fun <T> jacksonUnmapper(clazz: Class<T>, objectMapper: ObjectMapper = jacksonObjectMapper()): Unmapper<T> = {
+  objectMapper
+    .configureTaskpoolJacksonObjectMapper()
+    .convertValue(it, clazz)
 }
 
 /**
diff --git a/engine/taskpool-collector/src/test/kotlin/io/holunda/camunda/taskpool/sender/projectPropertiesTest.kt b/engine/taskpool-collector/src/test/kotlin/io/holunda/camunda/taskpool/sender/projectPropertiesTest.kt
index dc93a0406..b1e00498b 100644
--- a/engine/taskpool-collector/src/test/kotlin/io/holunda/camunda/taskpool/sender/projectPropertiesTest.kt
+++ b/engine/taskpool-collector/src/test/kotlin/io/holunda/camunda/taskpool/sender/projectPropertiesTest.kt
@@ -2,9 +2,9 @@
 
 package io.holunda.camunda.taskpool.sender
 
-import io.holunda.camunda.taskpool.sender.accumulator.ProjectionErrorDetector
-import io.holunda.camunda.taskpool.sender.accumulator.PropertyOperation
-import io.holunda.camunda.taskpool.sender.accumulator.projectProperties
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
+import io.holunda.camunda.taskpool.configureTaskpoolJacksonObjectMapper
+import io.holunda.camunda.taskpool.sender.accumulator.*
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.Test
 import java.util.*
@@ -12,11 +12,13 @@ import kotlin.reflect.KClass
 
 class PropertiesProjectorTest {
 
+  private val objectMapper = jacksonObjectMapper().configureTaskpoolJacksonObjectMapper()
+
   @Test
   fun `should return the command if details are empty`() {
 
     val model = model("Foo", "My foo model")
-    val result = projectProperties(model, projectionErrorDetector = object:ProjectionErrorDetector{})
+    val result = projectProperties(model, projectionErrorDetector = object:ProjectionErrorDetector{}, mapper = jacksonMapper(objectMapper), unmapper = jacksonUnmapper(model::class.java, objectMapper))
 
     assertThat(result).isEqualTo(model)
   }
@@ -25,7 +27,7 @@ class PropertiesProjectorTest {
   fun `should replace a detail`() {
 
     val model = model("Foo", "My foo model")
-    val result = projectProperties(model, listOf(named(name = "new name", id = model.id)), projectionErrorDetector = object:ProjectionErrorDetector{})
+    val result = projectProperties(model, listOf(named(name = "new name", id = model.id)), projectionErrorDetector = object:ProjectionErrorDetector{}, mapper = jacksonMapper(objectMapper), unmapper = jacksonUnmapper(model::class.java, objectMapper))
 
     assertThat(result).isEqualTo(model.copy(name = "new name"))
   }
@@ -37,7 +39,8 @@ class PropertiesProjectorTest {
     val result = projectProperties(model, listOf(
       named(name = "wrong name", id = model.id),
       named(name = "new name", id = model.id)),
-      projectionErrorDetector = object:ProjectionErrorDetector{}
+      projectionErrorDetector = object:ProjectionErrorDetector{},
+      mapper = jacksonMapper(objectMapper), unmapper = jacksonUnmapper(model::class.java, objectMapper)
     )
 
     assertThat(result).isEqualTo(model.copy(name = "new name"))
@@ -50,7 +53,7 @@ class PropertiesProjectorTest {
     val result = projectProperties(model, listOf(
       payload(payload = mutableMapOf("zee" to "test"), id = model.id),
       named(name = "new name", id = model.id)),
-      projectionErrorDetector = object:ProjectionErrorDetector{}
+      projectionErrorDetector = object:ProjectionErrorDetector{}, mapper = jacksonMapper(objectMapper), unmapper = jacksonUnmapper(model::class.java, objectMapper)
     )
 
     assertThat(result).isEqualTo(model.copy(name = "new name", enriched = true, payload = mutableMapOf("zee" to "test")))
@@ -73,7 +76,7 @@ class PropertiesProjectorTest {
           }
         }
       ),
-      projectionErrorDetector = object:ProjectionErrorDetector{}
+      projectionErrorDetector = object:ProjectionErrorDetector{}, mapper = jacksonMapper(objectMapper), unmapper = jacksonUnmapper(model::class.java, objectMapper)
     )
 
     assertThat(result).isEqualTo(model.copy(name = "new name", enriched = true, payload = mutableMapOf("foo" to "bar", "zee" to "test")))
@@ -103,7 +106,7 @@ class PropertiesProjectorTest {
           }
         }
       ),
-      projectionErrorDetector = object:ProjectionErrorDetector{}
+      projectionErrorDetector = object:ProjectionErrorDetector{}, mapper = jacksonMapper(objectMapper), unmapper = jacksonUnmapper(model::class.java, objectMapper)
     )
 
     // map elements should vanish, kermit remains alone in the list