使用 Transformers.toJson() 我的 json 日期如下所示:
"createdDate":{"year":2017,"month":"OCTOBER","monthValue":10,"dayOfMonth":25,"hour":7,"minute":57,"second":36," nano":972000000,"dayOfWeek":"WEDNESDAY","dayOfYear":298,"chronology":{"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'T'HH:mm:ss.SSSZ”
有什么办法可以覆盖spring集成使用的默认ObjectMapper?
例如,我在扩展 WebMvcConfigurerAdapter 的 Web api 配置中有此配置:
@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 或集成 ampq 中都是相同的?