如何让 Spring Integration Http.inboundGateway 返回 HAL Json?

问题描述

我将以下属性设置为 true“spring.hateoas.use-hal-as-default-json-media-type”并添加了 org.springframework.boot:spring-boot-starter-hateoas 作为依赖项。>

代码

@Bean
public IntegrationFlow myUserFlow() {
    return IntegrationFlows
            .from(Http.inboundGateway("/user")
                    .requestMapping(r -> r.methods(HttpMethod.GET))
                    .get()
            )
            .handle((payload,headers) -> new MyUser("Joe Blogs")
                    .add(Link.of("http://localhost:8080/account",LinkRelation.of("account"))))
            .get();
}

回复

GET http://localhost:8080/user
HTTP/1.1 200 
connection: Keep-Alive,keep-alive
Content-Type: application/hal+json;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon,11 Jan 2021 18:31:13 GMT
Keep-Alive: timeout=60

{
  "name": "Joe Blogs","links": [
    {
      "rel": "account","href": "http://localhost:8080/account"
    }
  ]
}

Response code: 200; Time: 19ms; Content length: 87 bytes

我希望以 HAL 格式返回响应,例如

{
  "name": "Joe Blogs","_links": [
    {
      "account":{
          "href": "http://localhost:8080/account"
       }
    }
  ]
}

为什么不是这样?我怎样才能做到这一点?

示例应用:https://github.com/kevvvvyp/si-hateoas-demo

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)