2015-04-01 78 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