使用Transformers.toJson()我的json日期如下所示:
" createdDate" {"一年":2017,"一个月":" 10月"" monthValue" :10,"请将dayOfMonth":25,"小时":7,"分钟":57,"第二":36,&#34 ;纳米":9.72亿,"一周中的某天":"星期三"" DAYOFYEAR":298,"年表" {&#34 ; calendarType":" ISO8601"" ID":" ISO"}}
这是出站ampq配置:
@Bean
public IntegrationFlow outboundCdrRabbitFlowDefinition() {
return IntegrationFlows.from(CHANNEL_NAME)
.transform(Transformers.toJson())
.handle(Amqp.outboundAdapter(new RabbitTemplate(cachingConnectionFactory))
.routingKey("routing-key"))
.get();
}
兔子队列的消费者期望格式" yyyy-MM-dd' HH:mm:ss.SSSZ"
有什么方法可以覆盖spring integration使用的默认ObjectMapper?
例如我在我的web api配置中有这个配置,它扩展了WebMvcConfigurerAdapter:
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setTimeZone(UTC_TIME_ZONE);
mapper.setDateFormat(ISO_8601_DATE_FORMAT);
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper;
}
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper());
return mappingJackson2HttpMessageConverter;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(mappingJackson2HttpMessageConverter());
super.configureMessageConverters(converters);
}
有没有办法在Spring Integration中重用objectMapper bean,所以我的所有出站端点,web api http或integration ampq的映射配置都是一样的?
答案 0 :(得分:1)
1.4.2
的重载版本:
Transformers.toJson()