【问题标题】:@jsonRootName not working with spring boot starter hateoas@jsonRootName 不适用于 Spring Boot 启动器 hatoas
【发布时间】:2015-06-06 07:01:59
【问题描述】:

我正在使用 spring-boot 和 spring-Hateoas 开发一个休息应用程序。我写的 DTO 是:

Bill.java

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonRootName("bills")
public class Bill{

依赖关系:

dependencies {
compile "org.springframework.boot:spring-boot-starter-hateoas"
compile "org.springframework.boot:spring-boot-starter-ws"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.cloud:spring-cloud-starter-eureka:${springCloudVersion}"

testCompile("org.springframework.boot:spring-boot-starter-test")
}

Application.java:

@Configuration
@Import(BillServiceConfig.class)
@EnableAutoConfiguration
@EnableEurekaClient
@ComponentScan({"com.billing"})
@EnableWebMvc
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
public class Application {

BillController.java:

 @RequestMapping(method = RequestMethod.GET, value = "")
 public ResponseEntity<Resources<Resource<Bill>>> getBills(@PathVariable String billUid)

我使用的 spring-boot 版本是 1.2.2。我得到的输出是

`_embedded: {
BillList:
{`

这里的 json Root 名称是 BillList。但我需要它作为“票据”而不是“BillList”。任何人都可以帮助解决这个问题。提前致谢。

【问题讨论】:

    标签: java spring spring-mvc spring-boot spring-hateoas


    【解决方案1】:

    _embedded 子句中的键实际上是关系名称。因此,它们是通过 Spring HATEOAS 中的 RelProvider 抽象获得的。自定义它们的最简单方法是使用 @Relation 注释域类型并定义您期望的项目和集合关系的关系名称。

    获取_embedded 子句中使用的正确复数的一种简单方法是将Evo Inflector JAR 添加到您的类路径中,如here 所述。

    【讨论】:

    • 我正在寻找一个示例,说明如何使用 @Relation 注释和 Evo Inflector JAR 在我的回复中正确设置 _embedded 子句。你知道有什么例子可以说明如何做到这一点吗?
    猜你喜欢
    • 2015-06-07
    • 1970-01-01
    • 2015-06-11
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 2015-04-13
    • 2018-10-18
    • 1970-01-01
    相关资源
    最近更新 更多