我一直在使用defaultMediaType配置屬性設置爲「application/json」來獲得「正常」的JSON,這更容易處理和我需要的全部:hal + json和普通json之間的spring-data-rest開關
{
"links": [
],
"content": [
{
"username": "admin",
"id": 1,
"authorities": [
"ROLE_ADMIN"
],
"content": [ ],
"links": [
{
"rel": "self",
"href": "http://localhost:8080/apiv1/data/users/1"
},
{
"rel": "logisUser",
"href": "http://localhost:8080/apiv1/data/users/1"
},
{
"rel": "mandant",
"href": "http://localhost:8080/apiv1/data/users/1/mandant"
}
]
},...
],
"page": {
"size": 20,
"totalElements": 3,
"totalPages": 1,
"number": 0
}
}
但它竟然是在集成測試impossible to use(不能與TestRestTemplate解組,也不能與Traverson等)。
使用hal + json與Traverson API很好地配合使用。
現在,因爲名稱是默認 MediaType和Spring Data Rest Reference始終提到「支持的媒體類型」,我希望使用「Accept」標題在兩個變體之間切換。但這並不起作用(還嘗試過「Content-Type」和兩者。使用「application/json和application/hal + json」)。
似乎還有一個屬性「useHalAsDefaultJsonMediaType」,但根本沒有做任何事情,據我所知。
那麼所有的希望都失去了嗎?爲什麼文檔如此混亂?有一種方法可以在表示之間進行切換,這不符合名稱的含義。沒有書面的方式來反序列化「舊」表示,新的表示不能用於TestRestTemplate。非常非常令人沮喪。我花了這個大量的時間已經:(