2015-04-01 83 views
2

我正在开发一个使用spring-boot和使用spring-Hateoas的休息应用程序。而我写的DTO是:@jsonRootName不适用于春季启动启动器讨厌

Bill.java

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

Depedencies:

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) 

而我使用的弹簧启动版本是1.2.2。我得到的输出是

`_embedded: { 
BillList: 
{` 

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

回答

2

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

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

+0

我正在寻找一个如何在我的响应中正确使用'@ Relation'注释和Evo Inflector JAR来获取'_embedded'子句设置的示例。你知道任何示例说明如何做到这一点吗? – Gillfish 2016-02-27 21:46:49