2016-09-18 38 views
0

當我調用Spring Data Rest Endpoint時,我期望看到每個對象中的自鏈接和相關鏈接。沒有任何鏈接出現。在使用RestTemplate的Spring Data Rest Response中缺失鏈接

RestTemplate設置:

@HystrixCommand(fallbackMethod = "getFallbackScenicList") 
@RequestMapping(value = "/s", method = RequestMethod.GET, produces= MediaType.APPLICATION_JSON_VALUE) 
public PagedResources<Scenic> scenic() { 
    String url = "http://vr-dms-an-scenic/scenic"; 
    ParameterizedTypeReference<PagedResources<Scenic>> ptr = new ParameterizedTypeReference<PagedResources<Scenic>>() {}; 

    ResponseEntity<PagedResources<Scenic>> responseEntity = 
     this.restTemplate.exchange(url,HttpMethod.GET, null, ptr, 0,100 
     ); 

    PagedResources<Scenic> resources = responseEntity.getBody(); 

    return resources; 
} 

預期的響應:

{ 
    "_embedded": { 
     "scenic": [ 
      { 
       "id": 1, 
       "name": "Test1 scenic", 
       "description": "This is a description1 for displaying information while in development", 
       "shortDescription": "Short Description Scenic1", 
       "_links": { 
        "self": { 
         "href": "http://localhost:49218/scenic/1" 
        }, 
        "scenic": { 
         "href": "http://localhost:49218/scenic/1" 
        } 
       } 
      } 
     ] 
    }, 
    "_links": { 
     "self": { 
      "href": "http://localhost:49218/scenic" 
     }, 
     "profile": { 
      "href": "http://localhost:49218/profile/scenic" 
     }, 
     "search": { 
      "href": "http://localhost:49218/scenic/search" 
     } 
    }, 
    "page": { 
     "size": 20, 
     "totalElements": 1, 
     "totalPages": 1, 
     "number": 0 
    } 
} 

實際響應:

{ 
    "_embedded": { 
     "scenic": [ 
      { 
       "id": 1, 
       "name": "Test1 scenic", 
       "description": "This is a description1 for displaying information while in development", 
       "shortDescription": "Short Description Scenic1" 
      } 
     ] 
    }, 
    "_links": { 
     "self": { 
      "href": "http://localhost:49218/scenic" 
     }, 
     "profile": { 
      "href": "http://localhost:49218/profile/scenic" 
     }, 
     "search": { 
      "href": "http://localhost:49218/scenic/search" 
     } 
    }, 
    "page": { 
     "size": 20, 
     "totalElements": 1, 
     "totalPages": 1, 
     "number": 0 
    } 
} 

回答

2

我認爲Scenic不包含鏈接。因此,而不是

PagedResources<Scenic> 

你真正想要

PagedResources<Resource<Scenic>> 
+0

嗯,這很容易。謝謝。 – code

相關問題