【问题标题】:Spring integration Java DSL: How to create the JSON in the integration flowSpring 集成 Java DSL:如何在集成流中创建 JSON
【发布时间】:2018-10-04 12:26:56
【问题描述】:

如何在集成流程中创建 JSON。我想发送 JSON

{
   "username": "user",
   "password": "password1"
}

到网址http://localhost:8051/session

我的集成流构建器是:

.integrationFlowBuilder
.handle(Http.outboundGateway("http://localhost:8051/session")
            .httpMethod(HttpMethod.POST).expectedResponseType(String.class))

【问题讨论】:

    标签: spring spring-integration spring-integration-dsl


    【解决方案1】:

    我认为我们需要更多关于此事的背景信息...

    你可以在transform()中静态创建这样一个JSON字符串:

    .transform(p -> "{
       \"username\": \"user\",
       \"password\": \"password1\"
    }")
    

    你有一些关于这件事的 POJO,它可以通过 RestTemplate 中的 MappingJackson2HttpMessageConverter 自动转换为 JSON。

    您也可以在发送到Http.outboundGateway() 之前使用ObjectToJsonTransformer

    所以,请告诉我们您目前拥有的更多信息以及您希望将哪种信息转换为 JSON。

    【讨论】:

    • 谢谢!这时候静态 JSON 字符串就足够了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-01
    • 2016-07-07
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    相关资源
    最近更新 更多