question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query responses are serialized with the Default Serializer instead of the Message Serializer

See original GitHub issue

Basic information

  • Axon Framework version: 4.5.8
  • JDK version: 11
  • Complete executable reproducer if available (e.g. GitHub Repo):

Steps to reproduce

This scenario describes what I was doing at that time, but it can be reproduced in many other ways.

My Event Serializer and Message Serializer (as defined in the doc) are configured to use Jackson. I do not configure the default Serializer, meaning it will use the XStream implementation by default.

I implemented a PageResponseType as explained in this issue comment for my query responses.

When sending a query expecting a PageResponseType response, I ended up with an XStream security exception.

Expected behaviour

I expected XStream not to be involved in the serialization of the response, but rather Jackson because I configured a Message Serializer for Axon Framework.

Actual behaviour

XStream was used as a serializer implementation, meaning Axon’s default Serializer was used, resulting in an error in my case (because I did not explicitly configure XStream to allow my response class, but this is another matter).


To summarize, reading the docs made me believe that the Message Serializer would be used for Query messages AND Query responses, but it seems to be used only for the Query message, leaving the Query response to the default serializer. Is this intentional? If yes, then this issue should not be a bug report but I would really like to see this explained in the documentation.

As a side note, this behavior may be the same for Command responses, but I did not test it.

Cheers!

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Arnaud-Jcommented, May 25, 2022

Everything makes sense in my head now! Thank you again for taking the time to give so much details!

1reaction
Arnaud-Jcommented, May 25, 2022

Ah I think I get it! Thanks for taking the time to explain.
Let me rephrase so I can be sure I get it right.

I indeed have a PageResponseType describing the type of response I expect, which is a custom Page implementation.
So I have this scenario in mind:

  1. Send a FindAllSomethingQuery query through the query gateway specifying that a PageResponseType(Something.class) is expected:
    • the message serializer is used to serialize the payload and metadata of the query
    • the default serializer is used to serialize the expected response type (and any other Axon-specific stuff that I do not know about)
  2. Axon Server routes the query to the correct application
    • the message serializer is used to deserialize the payload and metadata of the query into a FindAllSomethingQuery instance
    • the default serializer is used to deserialize the expected response type (and any other Axon-specific stuff that I do not know about)
  3. A @QueryHandler method returns a Page<Something> as the response data
    • the message serializer is used to serialize the actual response data, meaning a Page<Something>
  4. Axon Server routes the response data to the application that sent the query
    • the message serializer is used to deserialize the response data into a Page<Something> instance

@smcvb Is this scenario correct?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serializers - Django REST framework
To serialize a queryset or list of objects instead of a single object instance, you should pass the many=True flag when instantiating the ......
Read more >
Django rest framework, use different serializers in the same ...
For the case in question, which is about using a different serializer for list and retrieve actions, you have the problem that both...
Read more >
Serializers - Django REST framework - Tom Christie
Serializers allow complex data such as querysets and model instances to be converted to native Python datatypes that can then be easily rendered...
Read more >
Formats, Serializers, and Deserializers
Use the serializer and deserializer for your schema format. Specify the serializer in the code for the Kafka producer to send messages, and...
Read more >
Serializing Django objects
Call the serializer on the object (or objects) that you want to serialize, and the output will be a complete representation of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found