0

When I make a call to a Spring Data Rest Endpoint I am expecting to see the self links and related links within each object. None of the links appear.

RestTemplate Setup:

@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;
}

Expected Response:

{
    "_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
    }
}

Actual Response:

{
    "_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
    }
}
code
  • 4,073
  • 3
  • 27
  • 47

1 Answers1

2

I assume that Scenic doesn't contain links. So instead of

PagedResources<Scenic>

you actually want

PagedResources<Resource<Scenic>>
a better oliver
  • 26,330
  • 2
  • 58
  • 66