ResponseTypes.multipleInstancesOf(Class) does not return the given class type

When i use ResponseTypes.instanceOf(AandachtspuntAlgemeenBeeldView.class) i get respons with the given class .

    public List<AandachtspuntAlgemeenBeeldView> getAandachtspuntenAlgemeenBeeld(UUID onderzoekId) {
        AandachtspuntAlgemeenBeeldView algemeenBeeldViews = queryGateway.subscriptionQuery(
                        FetchAandachtspuntenViewQuery.builder().onderzoekId(onderzoekId).build(),
                        ResponseTypes.instanceOf(AandachtspuntAlgemeenBeeldView.class),
                        ResponseTypes.instanceOf(AandachtspuntAlgemeenBeeldView.class)
                )
                .initialResult()
                .block();
        return List.of(algemeenBeeldViews);
    }


    @QueryHandler
    @Transactional(readOnly = true)
    public AandachtspuntAlgemeenBeeldView fetchAandachtspuntAlgemeenBeeldViewQuery(FetchAandachtspuntenViewQuery fetchAandachtspuntViewQuery) {
        return aandachtspuntAlgemeenBeeldViewRepository.findAllByOnderzoekId(
                fetchAandachtspuntViewQuery.getOnderzoekId()
        ).stream().findFirst().orElse(null);
    }

But when i use the ResponseTypes.multipleInstancesOf(AandachtspuntAlgemeenBeeldView.class) bi do’nt get a list with the requested class type.
In this case i get an exception.

    public List<AandachtspuntAlgemeenBeeldView> getAandachtspuntenAlgemeenBeeld(UUID onderzoekId) {
        List<AandachtspuntAlgemeenBeeldView> algemeenBeeldViews = queryGateway.subscriptionQuery(
                        FetchAandachtspuntenViewQuery.builder().onderzoekId(onderzoekId).build(),
                        ResponseTypes.multipleInstancesOf(AandachtspuntAlgemeenBeeldView.class),
                        ResponseTypes.multipleInstancesOf(AandachtspuntAlgemeenBeeldView.class)
                )
                .initialResult()
                .block();
        return algemeenBeeldViews;
    }

    @QueryHandler
    @Transactional(readOnly = true)
    public List<AandachtspuntAlgemeenBeeldView> fetchAandachtspuntenAlgemeenBeeldViewQuery(FetchAandachtspuntenViewQuery fetchAandachtspuntViewQuery) {
        return aandachtspuntAlgemeenBeeldViewRepository.findAllByOnderzoekId(
                fetchAandachtspuntViewQuery.getOnderzoekId()
        );
    }

The exception i get is:
java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class nl.ind.onderzoek.domain.query.ui.aandachtspunt.AandachtspuntAlgemeenBeeldView (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; nl.ind.onderzoek.domain.query.ui.aandachtspunt.AandachtspuntAlgemeenBeeldView is in unnamed module of loader 'app')

whit debugging i cannot identify the class name of the returned object, seems the object in the query response is not mapped on the type given in multipleInstancesOf()

I am working with Axon 4.5.15.

It might be the problem that both use the same Query object. Does it still happen when you use a specific query when you want multiple instances?

Hello,
When I am testing I use one specific Query object and one QueryHandler.
So the described cases are 2 separate test runs with one query object and unique QueryHandler.

When i uses ResponseTypes.multipleInstancesOf() then i get the response as shown in the picture from the queryGateway.subscriptionQuery(...).initialResult().block();

Is there anything i have to extra or configure or whatever for the multiple Instances response?

might be related:

I would reccomend creating a new type which is a wrapper for the list and just return that (as a single response type).

It likely is an issue related to serialization. Do you use Jackson or XStream? Can you add an interceptor and log the serialized format of the list?

Thanks for the input, but wrapping the list and using a single response type is no solution, that’s a work around. keeps the problem alive.

I think this is an underlying Jackson issue (not an Axon one). Could you confirm you are using Jackson as the Serializer?

1 Like

The hint for the related problem seems the solution
I am integration testing with the following serializer configuration:

    @Bean
    @Primary
    public Serializer defaultSerializer( ) {
        ObjectMapper mapper = JacksonSerializer.defaultSerializer().getObjectMapper();
        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        mapper.activateDefaultTyping(
                mapper.getPolymorphicTypeValidator(),
                ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE
        );

        return JacksonSerializer.builder()
                .objectMapper(mapper)
                .lenientDeserialization()
                .build();
    }

changed the public Serializer defaultSerializer( ObjectMapper mapper) to defaultSerializer( ) because the Spring MVC serialized objects where affected and, we only whant the Query response objects being involved.

1 Like

Next problem with the serializer.
when using the serializer as described above i can do IT tests which uses the whole package with Commands and Events.
But when i start up the application i get AxonConfiguration exception

"stack_trace":"org.springframework.context.ApplicationContextException: Failed to start bean 'org.axonframework.spring.config.AxonConfiguration'; nested exception is org.axonframework.lifecycle.LifecycleHandlerInvocationException: One of the start handlers in phase [null] failed with the following exception:\n\tat org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)\n\tat org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)\n\tat org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)\n\tat java.base/java.lang.Iterable.forEach(Unknown Source)\n\tat org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)\n\tat org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)\n\tat org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:937)\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)\n\tat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:307)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)\n\tat nl.ind.onderzoek.OnderzoekServic
eApplication.main(OnderzoekServiceApplication.java:10)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\n\tat java.base/java.lang.reflect.Method.invoke(Unknown Source)\n\tat org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)\n\tat org.springframework.boot.loader.Launcher.launch(Launcher.java:108)\n\tat org.springframework.boot.loader.Launcher.launch(Launcher.java:58)\n\tat org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)\nCaused by: org.axonframework.lifecycle.LifecycleHandlerInvocationException: One of the start handlers in phase [null] failed with the following exception:\n\tat org.axonframework.config.DefaultConfigurer.lambda$invokeStartHandlers$35(DefaultConfigurer.java:705)\n\tat org.axonframework.config.DefaultConfigurer.invokeLifecycleHandlers(DefaultConfigurer.java:756)\n\tat org.axonframework.config.DefaultConfigurer.invokeStartHandlers(DefaultConfigurer.java:699)\n\tat org.axonframework.config.DefaultConfigurer$ConfigurationImpl.start(DefaultConfigurer.java:824)\n\tat org.axonframework.spring.config.AxonConfiguration.start(AxonConfiguration.java:199)\n\tat org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)\n\t... 22 common frames omitted\nCaused by: java.util.concurrent.ExecutionException: org.axonframework.lifecycle.LifecycleHandlerInvocationException: Failed during invocation of lifecycle handler [public void org.axonframework.axonserver.connector.processor.EventProcessorControlService.start()] on component [org.axonframework.axonserver.connector.processor.EventProcessorControlService@16335685]\n\tat java.base/java.util.concurrent.CompletableFuture.reportGet(Unknown Source)\n\tat java.base/java.util.concurrent.CompletableFuture.get(Unknown Source)\n\tat org.axonframework.config.DefaultConfigur
er.invokeLifecycleHandlers(DefaultConfigurer.java:754)\n\t... 26 common frames omitted\nCaused by: org.axonframework.lifecycle.LifecycleHandlerInvocationException: Failed during invocation of lifecycle handler [public void org.axonframework.axonserver.connector.processor.EventProcessorControlService.start()] on component [org.axonframework.axonserver.connector.processor.EventProcessorControlService@16335685]\n\tat org.axonframework.config.LifecycleHandlerInspector.invokeAndReturn(LifecycleHandlerInspector.java:128)\n\tat org.axonframework.config.LifecycleHandlerInspector.lambda$null$0(LifecycleHandlerInspector.java:91)\n\tat java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)\n\tat java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)\n\tat java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)\n\tat java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)\n\tat java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)\n\tat java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)\n\tat java.base/java.util.stream.ReferencePipeline.reduce(Unknown Source)\n\tat org.axonframework.config.DefaultConfigurer.invokeLifecycleHandlers(DefaultConfigurer.java:752)\n\t... 26 common frames omitted\nCaused by: java.lang.reflect.InvocationTargetException: null\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\n\tat java.base/java.lang.reflect.Method.invoke(Unknown Source)\n\tat org.axonframework.config.LifecycleHandlerInspector.invokeAndReturn(LifecycleHandlerInspector.java:121)\n\t... 35 common frames omitted\nCaused by: org.axonframework.eventhandling.tokenstore.UnableToRetrieveIdentifierException: Exception occurred while trying to establish storage identifier\n\tat org.axonframework.eventhandling.tokensto
re.jpa.JpaTokenStore.retrieveStorageIdentifier(JpaTokenStore.java:265)\n\tat org.axonframework.eventhandling.TrackingEventProcessor.lambda$calculateIdentifier$4(TrackingEventProcessor.java:251)\n\tat org.axonframework.common.transaction.TransactionManager.fetchInTransaction(TransactionManager.java:70)\n\tat org.axonframework.eventhandling.TrackingEventProcessor.calculateIdentifier(TrackingEventProcessor.java:250)\n\tat org.axonframework.eventhandling.TrackingEventProcessor.lambda$getTokenStoreIdentifier$3(TrackingEventProcessor.java:246)\n\tat java.base/java.util.concurrent.atomic.AtomicReference.updateAndGet(Unknown Source)\n\tat org.axonframework.eventhandling.TrackingEventProcessor.getTokenStoreIdentifier(TrackingEventProcessor.java:246)\n\tat org.axonframework.axonserver.connector.processor.StreamingEventProcessorInfoMessage.describe(StreamingEventProcessorInfoMessage.java:58)\n\tat org.axonframework.axonserver.connector.processor.EventProcessorControlService.lambda$infoSupplier$1(EventProcessorControlService.java:115)\n\tat io.axoniq.axonserver.connector.impl.ControlChannelImpl.lambda$sendScheduledProcessorInfo$3(ControlChannelImpl.java:245)\n\tat java.base/java.util.concurrent.ConcurrentHashMap$ValuesView.forEach(Unknown Source)\n\tat io.axoniq.axonserver.connector.impl.ControlChannelImpl.sendScheduledProcessorInfo(ControlChannelImpl.java:245)\n\tat io.axoniq.axonserver.connector.impl.ControlChannelImpl.registerEventProcessor(ControlChannelImpl.java:226)\n\tat org.axonframework.axonserver.connector.processor.EventProcessorControlService.lambda$start$0(EventProcessorControlService.java:105)\n\tat java.base/java.util.HashMap.forEach(Unknown Source)\n\tat org.axonframework.axonserver.connector.processor.EventProcessorControlService.start(EventProcessorControlService.java:103)\n\t... 40 common frames omitted\nCaused by: org.axonframework.serialization.SerializationException: Error while deserializing object\n\tat org.axonframework.serialization.json.JacksonSerializer.deserialize(JacksonSerializer.java:203)\n\ta
t org.axonframework.eventhandling.tokenstore.AbstractTokenEntry.getToken(AbstractTokenEntry.java:121)\n\tat org.axonframework.eventhandling.tokenstore.jpa.JpaTokenStore.getConfig(JpaTokenStore.java:278)\n\tat org.axonframework.eventhandling.tokenstore.jpa.JpaTokenStore.retrieveStorageIdentifier(JpaTokenStore.java:263)\n\t... 55 common frames omitted\nCaused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class java.util.Map\n at [Source: (byte[])\"{\"config\":{\"id\":\"931d2f6d-7e1e-4420-9eba-7dbeb193fbb6\"}}\"; line: 1, column: 11] (through reference chain: org.axonframework.eventhandling.tokenstore.ConfigToken[\"config\"])\n\tat com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)\n\tat com.fasterxml.jackson.databind.DeserializationContext.wrongTokenException(DeserializationContext.java:1939)\n\tat com.fasterxml.jackson.databind.DeserializationContext.reportWrongTokenException(DeserializationContext.java:1673)\n\tat com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer._locateTypeId(AsArrayTypeDeserializer.java:141)\n\tat com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer._deserialize(AsArrayTypeDeserializer.java:96)\n\tat com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer.deserializeTypedFromObject(AsArrayTypeDeserializer.java:61)\n\tat com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserializeWithType(MapDeserializer.java:482)\n\tat com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:539)\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:564)\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:439)\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDese
rializerBase.java:1405)\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:352)\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185)\n\tat com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)\n\tat com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2051)\n\tat com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1529)\n\tat org.axonframework.serialization.json.JacksonSerializer.deserialize(JacksonSerializer.java:201)\n\t... 58 common frames omitted\n"}

Any one a clue which serializer this is or how to make my bean only applicable for my QueryHandlers?

mmm, al this buggy stuff don’t give me much confidence in the Axon framework to be honest.

I also have CommandHandlers of AggregateMembers that won’t be reached. they completly seems non existing for the Aggregate, except when they are implemented in the AggregateRoot, but thats not what i want. I want to declutter my Aggregate root and do the aggregateMember stuf in this memeber self.

Totaly not happy at the moment :frowning:

It doesn’t really have to do with Axon Framework, but with sterilization. If you change the way serialization works, it’s possible the old tokens can’t be deserialized anymore. Can you create a separate issue for the aggregate member issue? It might help to move to the latest version, I know we did some fixes for aggregate members a while back.

For the serialization We have found that we have to start clean then things start to work.
for the AggregateMember problem i have this one on StackOverflow

1 Like

I am looking forward for the test project. I do hope moving to a newer version of the framework might already fix it.