Отсутствующие ссылки в Spring Data Rest Response с использованием RestTemplate

Когда я звоню в конечную точку Spring Data Rest, я ожидаю увидеть собственные ссылки и связанные ссылки внутри каждого объекта. Ни одна ссылка не появляется.

Настройка 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
    }
}

person code    schedule 18.09.2016    source источник


Ответы (1)


Я предполагаю, что Scenic не содержит ссылок. Итак, вместо

PagedResources<Scenic>

ты на самом деле хочешь

PagedResources<Resource<Scenic>>
person a better oliver    schedule 18.09.2016
comment
Что ж, это было легко. Спасибо. - person code; 18.09.2016