I have a SpringBoot application, using Camel for routing. For configuring jackson xmlMapper, I have the following spring bean:
@Bean
public XmlMapper xmlMapper() {
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
return xmlMapper;
}
And I want Camel to use this mapper when unmarshalling received POJOs as following:
from("direct:myRoute")
.marshal().jacksonxml()
.inOnly("activemq:outputQueue");
But it doesn't work this way: null fields are present in marshalled xml. Camel documentation offers to use JacksonXMLDataFormat as following:
JacksonXMLDataFormat format = new JacksonXMLDataFormat();
format.setInclude("NON_NULL");
from("direct:myRoute")
.marshal(format)
.inOnly("activemq:outputQueue");
It works, but I have to specify dataFormat each time I marshal something, and it gets trickier with unmarshalling.
Is there a unified way to configure Camel's xmlMapper?