spring-amqp icon indicating copy to clipboard operation
spring-amqp copied to clipboard

Add the body object to the ClassMapper.fromClass method

Open codemaker219 opened this issue 5 years ago • 3 comments

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?

codemaker219 avatar Apr 11 '19 10:04 codemaker219

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.

Contributions are welcome!.

garyrussell avatar Apr 11 '19 14:04 garyrussell

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.

codemaker219 avatar Apr 15 '19 13:04 codemaker219

Finally, I created an example (and tried to create a pull-request). See here https://github.com/codemaker219/classmapper-example/tree/master

codemaker219 avatar Apr 15 '19 14:04 codemaker219

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

artembilan avatar Jan 16 '24 20:01 artembilan