diff --git a/core/bus-jackson/src/main/kotlin/io/holunda/polyflow/bus/jackson/JsonAutoDetectAnyVisibility.kt b/core/bus-jackson/src/main/kotlin/io/holunda/polyflow/bus/jackson/JsonAutoDetectAnyVisibility.kt new file mode 100644 index 000000000..fc79c2fb9 --- /dev/null +++ b/core/bus-jackson/src/main/kotlin/io/holunda/polyflow/bus/jackson/JsonAutoDetectAnyVisibility.kt @@ -0,0 +1,9 @@ +package io.holunda.polyflow.bus.jackson + +import com.fasterxml.jackson.annotation.JsonAutoDetect + +/** + * Allow serialization of all fields. (Also private fields!) + */ +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) +class JsonAutoDetectAnyVisibility diff --git a/core/datapool/datapool-core/pom.xml b/core/datapool/datapool-core/pom.xml index a38ace6c2..6eca08da9 100644 --- a/core/datapool/datapool-core/pom.xml +++ b/core/datapool/datapool-core/pom.xml @@ -40,12 +40,11 @@ dom4j 2.1.4 - io.holunda.polyflow polyflow-bus-jackson - test + org.springframework.boot spring-boot-starter-test diff --git a/core/datapool/datapool-core/src/main/kotlin/io/holunda/polyflow/datapool/core/DataPoolCoreAxonConfiguration.kt b/core/datapool/datapool-core/src/main/kotlin/io/holunda/polyflow/datapool/core/DataPoolCoreAxonConfiguration.kt index d1acd8734..a3f6fd958 100755 --- a/core/datapool/datapool-core/src/main/kotlin/io/holunda/polyflow/datapool/core/DataPoolCoreAxonConfiguration.kt +++ b/core/datapool/datapool-core/src/main/kotlin/io/holunda/polyflow/datapool/core/DataPoolCoreAxonConfiguration.kt @@ -1,5 +1,7 @@ package io.holunda.polyflow.datapool.core +import com.fasterxml.jackson.databind.ObjectMapper +import io.holunda.polyflow.bus.jackson.JsonAutoDetectAnyVisibility import io.holunda.polyflow.datapool.core.business.CreateOrUpdateCommandHandler import io.holunda.polyflow.datapool.core.business.DataEntryAggregate import io.holunda.polyflow.datapool.core.business.upcaster.DataEntryCreatedEventUpcaster @@ -13,6 +15,7 @@ import org.axonframework.eventsourcing.SnapshotTriggerDefinition import org.axonframework.eventsourcing.Snapshotter import org.axonframework.eventsourcing.eventstore.EventStore import org.axonframework.messaging.annotation.ParameterResolverFactory +import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Qualifier import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.context.annotation.Bean @@ -98,5 +101,15 @@ class DataPoolCoreAxonConfiguration { */ @Bean(DATA_ENTRY_CACHE) fun dataEntryCache(): Cache = WeakReferenceCache() + + @Autowired + fun configureJackson(objectMapper: ObjectMapper) { + objectMapper.configurePolyflowJacksonObjectMapperForDatapool() + } +} + +fun ObjectMapper.configurePolyflowJacksonObjectMapperForDatapool(): ObjectMapper { + addMixIn(DataEntryAggregate::class.java, JsonAutoDetectAnyVisibility::class.java) + return this } diff --git a/core/datapool/datapool-core/src/test/kotlin/io/holunda/polyflow/datapool/core/business/DataEntryAggregateTest.kt b/core/datapool/datapool-core/src/test/kotlin/io/holunda/polyflow/datapool/core/business/DataEntryAggregateTest.kt index b72642785..2f6d34f81 100644 --- a/core/datapool/datapool-core/src/test/kotlin/io/holunda/polyflow/datapool/core/business/DataEntryAggregateTest.kt +++ b/core/datapool/datapool-core/src/test/kotlin/io/holunda/polyflow/datapool/core/business/DataEntryAggregateTest.kt @@ -2,8 +2,10 @@ package io.holunda.polyflow.datapool.core.business import com.fasterxml.jackson.databind.ObjectMapper import io.holunda.camunda.taskpool.api.business.* +import io.holunda.polyflow.bus.jackson.JsonAutoDetectAnyVisibility import io.holunda.polyflow.bus.jackson.configurePolyflowJacksonObjectMapper import io.holunda.polyflow.datapool.core.DeletionStrategy +import io.holunda.polyflow.datapool.core.configurePolyflowJacksonObjectMapperForDatapool import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat import org.axonframework.eventsourcing.AggregateDeletedException @@ -373,7 +375,9 @@ class DataEntryAggregateTest { @Test fun `should serialize and deserialize an aggregate with data`() { // GIVEN an object mapper and a filled aggregate - val objectMapper = ObjectMapper().configurePolyflowJacksonObjectMapper() + val objectMapper = ObjectMapper() + .configurePolyflowJacksonObjectMapper() + .configurePolyflowJacksonObjectMapperForDatapool() val dataEntryAggregate = DataEntryAggregate().apply { on(