Rob
Rob

Reputation: 43

Axon no Handler Found for query when returning Response with Generic

We are having issues when our Axon QueryHandler is returning a Class with a Generic parameter like QueryResult<T>. For example:

class QueryResult<T>(val values: List<T>, val status: Status,
                                 var text: String? = null) : Serializable {
...
}

And our query handler:

@QueryHandler
    fun handle(query: SomeQuery): QueryResult<String>{

Axon is giving us the following message:

NoHandlerForQueryException: No handler found for [SomeQuery] with response type [InstanceResponseType{class QueryResult}]

Is using Generics allowed in QueryHandlers or do we have to call queryGateway in some specific way?

Upvotes: 2

Views: 1804

Answers (1)

Steven
Steven

Reputation: 7275

Axon will only resolve generics for the following return types:

  • Collections
  • Futures
  • Optionals

I believe your desired query response would require a new implementation of the ResponeType interface, which will do even further inspection upon the available generics.

Short answer? What you're trying to do isn't possible at the moment.

The documentation is relative short on this, but still clear I think. If you disagree on that, you're free to provide a pull request or open up an issue to request for clarity on the matter.

Upvotes: 1

Related Questions