Spring Integration with Jackson ObjectMapper and Java 8 Time (JSR-310)

后端 未结 2 1752
野的像风
野的像风 2021-01-21 17:53

I am struggling with configuring a \"custom\" ObjectMapper to be used by the Spring Integration DSL transformers. I receive an java.time.Instant json representation

相关标签:
2条回答
  • 2021-01-21 18:15

    There is nothing to do with the Spring Boot on the matter to force Spring Integration to use that.

    You just need to configure JsonToObjectTransformer with that your jsonObjetMapper():

    @Bean
    @Transformer(inputChannel="input", outputChannel="output")
    JsonToObjectTransformer jsonToObjectTransformer() {
        return new JsonToObjectTransformer(jsonObjectMapper());
    }
    

    Although there is no reason to register JsonObjectMapper as a bean.

    0 讨论(0)
  • 2021-01-21 18:26

    Have you defined an encoder to your channel adapter?

    You should always use an encoder for whichever adapter you're using, inbound channel adapter or message drive channel adapter.

    In your case StringEncoder should solve the problem.

    <bean id="myEncoder" class="org.springframework.integration.kafka.serializer.common.StringEncoder"/>
    
    0 讨论(0)
提交回复
热议问题