Aggregate identifier is null Axon 3.0.6

  • Getting these warnings logs: “An attempt to create and store a snapshot resulted in an exception. Exception summary: 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.”
  • We use a Jackson serializer for the event store
  • error occurs when a new snapshot is being created
  • we see 8 of these errors but only 2 new events persist, thinking retry logic or something

Hi Katelyn,

With Jackson, especially for aggregates, special care needs to be taken to make sure all the fields that need to be serialized, are indeed serialized. One of those ways is to add a public getter for each of those fields, like the aggregate identifier.

It’s very likely currently stored without the aggregate identifier. Other fields might be missing as well. It’s also possible to set the visibility on the object mapper objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);

It seems this issue is back in my configuration of Axon 4.11 + Spring 3.4.5
Before I have no specific configuration than the ObjectMapper provided by Spring

public Serializer eventSerializer(ObjectMapper objectMapper) {
  return JacksonSerializer.builder()
      .objectMapper(objectMapper)
      .build();
}  

My current configuration worked fine with Spring 3.2.5, when upgraded to Spring 3.4.5 I started facing issues like below

org.axonframework.serialization.SerializationException: Error while deserializing payload of message de226d95-b893-4797-a156-c4e138820c60

and

at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 19] (through reference chain: 

It seems to be related to a important change on Jackson 2.16

To fix it the solution proposed by @Gerard worked like a charm :pray:

My question: Is there any better way to solve it? Although it worked now I need to run a full regression to be confident to release it in a service running for years without issues

The way I fixed it was by migrating my aggregate ID classes from static constructors ‘of’ to Java Record