Как указать, что моя конечная точка (или, в идеале, глобально: все конечные точки) требует преобразования POJO в формат application/json
перед отправкой?
Скажем, у меня есть контроллер REST, который вводит конечную точку в обмен rabbitmqи я хочу, чтобы объекты, которые я посылаю через этот обмен, были сериализованы в json, как-то так:
@RestController
public class Partners {
@EndpointInject(uri = "rabbitmq:core/partners/create")
private ProducerTemplate partnersCreate;
@RequestMapping("/partners/create")
public Partner create(Partner partner) {
return partnersCreate.requestBody(partner, Partner.class);
}
}
Но проблема в том, что верблюд, очевидно, понятия не имеет, что делать с POJO:
org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: com.example.core.client.model.Partner to the required type: byte[] with value com.example.core.client.model.Partner@29069cf5
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:206) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.component.rabbitmq.RabbitMQMessagePublisher.publish(RabbitMQMessagePublisher.java:86) ~[camel-rabbitmq-2.21.1.jar:2.21.1]
at org.apache.camel.component.rabbitmq.RabbitMQEndpoint.publishExchangeToChannel(RabbitMQEndpoint.java:216) ~[camel-rabbitmq-2.21.1.jar:2.21.1]
at org.apache.camel.component.rabbitmq.RabbitMQProducer$2.doWithChannel(RabbitMQProducer.java:289) ~[camel-rabbitmq-2.21.1.jar:2.21.1]
at org.apache.camel.component.rabbitmq.RabbitMQProducer$2.doWithChannel(RabbitMQProducer.java:286) ~[camel-rabbitmq-2.21.1.jar:2.21.1]
at org.apache.camel.component.rabbitmq.RabbitMQProducer.execute(RabbitMQProducer.java:90) ~[camel-rabbitmq-2.21.1.jar:2.21.1]
at org.apache.camel.component.rabbitmq.RabbitMQProducer.basicPublish(RabbitMQProducer.java:286) ~[camel-rabbitmq-2.21.1.jar:2.21.1]
at org.apache.camel.component.rabbitmq.RabbitMQProducer.processInOut(RabbitMQProducer.java:244) ~[camel-rabbitmq-2.21.1.jar:2.21.1]
at org.apache.camel.component.rabbitmq.RabbitMQProducer.process(RabbitMQProducer.java:193) ~[camel-rabbitmq-2.21.1.jar:2.21.1]
at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:186) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:86) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:541) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:506) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:369) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:506) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:264) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:325) ~[camel-core-2.21.1.jar:2.21.1]
at com.example.admin.backend.api.Partners.create(Partners.java:16) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
Несмотря на то, что
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson-starter</artifactId>
<version>2.21.1</version>
</dependency>
присутствует в pom.xml.Я предполагаю, что помимо простой регистрации формата данных, я должен как-то сказать Camel использовать его, но в настоящее время задаюсь вопросом, как именно.