【发布时间】:2014-01-15 17:03:37
【问题描述】:
我正在使用配置了 @EnableHypermediaSupport(type = HAL) 的 Spring Boot 和 Spring Hateoas。虽然这在基本场景中可以正常工作,但我希望能够向链接添加其他属性。例如,很容易返回将呈现如下链接的链接:
{
"_links":{
"self":{
"href":"http://localhost/"
},
"something":[
{
"href":"http://some-url.com/something1"
},
{
"href":"http://some-url.com/something2"
}
]
}
我想要做的是在 something rel 中为对象添加更多属性。例如:
{
"_links":{
"self":{
"href":"http://localhost/"
},
"something":[
{
"name":"something1",
"href":"http://some-url.com/something1"
},
{
"name":"something2",
"href":"http://some-url.com/something2"
}
]
}
}
在不创建自己的 DTO 的情况下,最好的方法是什么(最好使用 ControllerLinkBuilder)?我尝试创建自己的 Link 子类并为名称(以及 getter 和 setter)添加字段,但它们似乎被忽略了。
【问题讨论】:
标签: json spring-mvc spring-hateoas hal-json