JSON Serialization for Event Payload Data

Hi Team,
We are using Axon Framework 4.7.3 and AxonServer 2023.1.0 in SE mode with SpringBoot 3.1.0.
In the event payload we are persisting a BusinessEvent object which is complex CDM interface class with lot of fields. When we serialize this object, it does not have all the fields initialized.

When we read the payload from AxoniQ server UI(http://localhost:8024/#query) the resultant JSON only shows the values we initialized.

But when we are try to read the event payload programmatically through EventStore interface, the resultant object has all the fields of BusinessEvent object. Those we had set during the serialization along with rest fields set as null like below. How can we avoid getting fields with null value in this case?

"instruction": [
        "before": {
            "externalReference": null,
            "globalReference": null,
            "reference": null,
            "value": {
                "meta": null,
                "observationHistory": null,
                "resetHistory": null,
                "state": {
                     "closedState": null,
                     "positionState": "EXECUTED",
                     "type": "cdm.event.common.State"

I have a hunch this has to do with the JacksonSerializer, and/or ObjectMapper configuration.
A quick ‘Google’ led me to this Baeldung page about ignoring null fields for Jackson.

To paraphrase what’s there, you can take two routes:

  1. Specify on the object-to-serialize to ignore null fields.
  2. Specify on the ObjectMapper to ignore null fields for any object-to-serialize.

Thus, you could adjust this BusinessEvent to contain the @JsonInclude(Include.NON_NULL) annotation on the class.
Or, you adjust the ObjectMapper (for Axon Framework’s JacksonSerializer) by invoking ObjectMapper#setSerializationInclusion(Include) with JsonInclude.Include.NON_NULL.

Please give that a try and let us know whether it solves your predicament, @Shrirang_Khedekar!

Thank you team for your response. It was indeed an issue with serialization but not with Axon interface. We had overridden axon’s de/seserialization with our custom ObjectMapper which would manage the nulls. Based on that axon was doing the serialization and deserialization properly. We found that after reading the eventpayload from eventstore we were sending that data to client as API response. So in this process, the this eventpayload was getting serialized again using default ObjectMapper of Jackson. By using our custom 'ObjectMapper` there, the issue got resolved. So it was not an axon issue.

Thanks for sharing that with us, @Shrirang_Khedekar!
Replying with your findings and solutions is beneficial to all people on this forum.
Hence, it is very much appreciated that you’re adding your findings.