spring-amqp
spring-amqp copied to clipboard
Add the body object to the ClassMapper.fromClass method
I have written a custom InvocableHandlerMethod
. Basically, it wraps the response of an RPC call in a in another object. With this, I can catch specific exceptions. So, the wrapper class contains ether the result or an exception. Nevertheless, the wrapper class is in my case a generic class. By the way I use the Jackson2JsonMessageConverter
for json serialisation. Unfortunately, the header of the Rabbitmq-Message is set to the class of the response type of the rabbit-listener-method (Somewhere on the HandlerAdapter.invoke(…)
). Since I wrap the response to another object, the header is not set correctly. Fortunately, I can give the Jackson2JsonMessageConverter
a class ClassMapper
so I can change the TypeId-Header.
Unfortunately the ClassMapper
only get the class of the body-object. Since my wrapper-class is generic I cannot determine the typeparamater.
Here is my question: Is it possible to change the ClassMapper
-Interface, in a way, that the fromClass
-Mathod also get the body-object and not only its class?
I am not sure I fully understand the use case, but with Java 8 and default methods it's easy to make non-breaking changes to interfaces, so I have no objections.
Thank you for your response. I am creating a small example so you can see what I am trying to do.
During I put all things together I noticed that this change will not be enough (sorry for that).
I also need the ClassMapper.toClass(...)
method to return a JavaType
or a ParameterizedTypeReference
to express a generic type.
So, in the fromClass
Method I will write everything I need for the generic Type in the header and in the toClass
Method a want to extract all this information and construct this typ.
Finally, I created an example (and tried to create a pull-request). See here https://github.com/codemaker219/classmapper-example/tree/master
I don't see a reason in all of this since we have a more advance Jackson2JavaTypeMapper
strategy which is an extension of the mentioned ClassMapper
with all the expected logic.
Closing as Won't Fix