Axon MongoDB Extension with Jackson Snapshot configuration

Hello I try to configure MongoDB Extension with Jackson.

I used the wallet show case for it. GitHub - marzelwidmer/axon-wallet: Based on : https://youtu.be/15hzHUI4WNA

The Application works fine with the XSteam Settings. and also When I configure the MongoDB eventSerializer with Jackson.

I have issues when I configure the snapshotSerializer also with my Jackson Settings.

Question : Can I mix this ?

and have maybe somebody any idea how to fix this ?


    /**
     * Create a Mongo based Event Storage Engine.
     */
    @Bean
    fun storageEngine(client: MongoClient?): EventStorageEngine = MongoEventStorageEngine.builder()
        .eventSerializer(jacksonMessageSerializer())
        .snapshotSerializer(jacksonMessageSerializer())
        .mongoTemplate(
            DefaultMongoTemplate
                .builder()
                .mongoDatabase(client)
                .build()
        ).build()


    // But for all our messages we'd prefer the JacksonSerializer due to JSON's smaller format
    @Bean
    @Qualifier("messageSerializer")
    fun jacksonMessageSerializer(): Serializer {
        val objectMapper = ObjectMapper()
        objectMapper.registerModule(KotlinModule.Builder().build())
        objectMapper.registerModule(JavaTimeModule())
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
            .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
        return JacksonSerializer.builder()
            .objectMapper(objectMapper)
            .lenientDeserialization()
            .build()
    }

    @Bean
    @Qualifier("messageSerializer")
    fun messageSerializer(): Serializer = XStreamSerializer.builder()
        .xStream(xStream())
        .build()

    fun xStream(): XStream {
        val xStream = XStream()
        xStream.allowTypesByWildcard(
            arrayOf(
                "org.axonframework.**",
                "**",
            )
        )
        return XStreamSerializer.builder().xStream(xStream).build().xStream
    }

org.axonframework.eventsourcing.IncompatibleAggregateException: Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event.
	at org.axonframework.eventsourcing.EventSourcedAggregate.publish(EventSourcedAggregate.java:256) ~[axon-eventsourcing-4.5.9.jar:4.5.9]
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
	*__checkpoint ⇢ Handler ch.keepcalm.axon.wallet.api.WalletCommandController#createWallet(Continuation) [DispatcherHandler]
	*__checkpoint ⇢ org.springframework.web.filter.reactive.ServerWebExchangeContextFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ HTTP GET "/command/create" [ExceptionHandlingWebHandler]
Original Stack Trace:

Hi Marzel,

I tried to move the demo project included in the extension to Jackson. I think I ran into the same problem there. With Jackson you need public getters to serialize private fields. So hopefully adding those to WalletAggregate should fix it. Please let us know if that helps.

1 Like