Serializing an AbstractAnnotatedAggregateRoot<Tree> with Jackson goes wrong..

165 views
Skip to first unread message

Stefan Pries

unread,
Aug 16, 2016, 12:57:32 PM8/16/16
to Axon Framework Users
Hello everyone!

I try to serialize a Class (Tree) that extends the AbstractAnnotatedAggregateRoot<Tree> and has 2 fields: private String treeId and private int rings.
As I run the serialization I get

com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.axonframework.domain.SimpleDomainEventStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: [...])

The reason for this error is, I am pretty sure, that Jackson tries to serialize the fields that are extended by the superclass.
I read that it might be a good idea to use the composite pattern instead of inheriting from AbstractAnnotatedAggregateRoot,
and it would be easy (or at least easier) to tell Jackson to ignore that field. What would it look like? Is it an option? If not:
Does anyone have an idea, what a clean and fast fix for this issue could be?

I'd be glad if someone could help me,
Thanks a lot!

robert


Steven Grimm

unread,
Aug 16, 2016, 1:15:47 PM8/16/16
to Axon Framework Users
This shouldn't be an issue in Axon 3, which no longer requires your aggregate classes to extend an Axon superclass. If the timing of your project allows it, you might look at the 3.0 milestone releases.

What are you using the serialized object for? The use case will influence the best answer to your question absent moving to Axon 3.

One possibility: you could add Jackson annotations to control the serialization behavior.

If you are using event sourcing you will want to be careful about serializing aggregates on your own since the aggregate object is not the source of truth; it is more like a view of the event stream.

-Steve

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stefan Pries

unread,
Aug 22, 2016, 3:48:14 AM8/22/16
to Axon Framework Users
Hey,

sorry for the delay, I have been off a couple days.
To make it short:
1. I committed to use axon 2 for now.
2. I wanted to send a change of my aggregate to another service, that would be interested in it, be sending the whole thing.
3. Jackson Annotation do not make it easy to ignore all base class fields (and it is ugly).
4. I fixed it, by attaching the specific fields to the event, and not the whole aggregate.

Thanks for the help!
Regards!
Reply all
Reply to author
Forward
0 new messages