Generic Entity Members

Hello,

I wanted to have some entity members in my aggregate to be of a generic type. When I tried to run my code, Axon Framework complained that it was not able to cast the object to a Class object.

The code that did not work was:

@AggregateMember(eventForwardingMode = ForwardMatchingInstances::class)
val fields: MutableMap<String, PoolFieldEntity<*>> = mutableMapOf()

The error message returned was the following:

    Caused by: java.lang.ClassCastException: class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to class java.lang.Class (sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl and java.lang.Class are in module java.base of loader 'bootstrap')
	at org.axonframework.common.ReflectionUtils.resolveMemberGenericType(ReflectionUtils.java:356) ~[axon-messaging-4.4.3.jar:4.4.3]

Did I do something wrong or is my intention generally a bad way to solve the problem?

Thank you very much for your help in advance.

1 Like

This problem should be covered by providing the type of the member inside the annotation.
You can use the type field on the annotation for that.
Would you mind giving that a try to see of the problem persists?