Skip to content

Commit

Permalink
Allow serialization of private fields for data entry aggregate #978
Browse files Browse the repository at this point in the history
  • Loading branch information
p-wunderlich committed Apr 19, 2024
1 parent b315b4d commit c40728d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions core/datapool/datapool-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@
<artifactId>dom4j</artifactId>
<version>2.1.4</version>
</dependency>

<dependency>
<groupId>io.holunda.polyflow</groupId>
<artifactId>polyflow-bus-jackson</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}

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

0 comments on commit c40728d

Please sign in to comment.