diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java index 2863ab312..e8fcfbe87 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java @@ -18,7 +18,6 @@ package org.springframework.data.rest.webmvc.support; import static org.assertj.core.api.Assertions.*; import org.junit.Test; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; @@ -157,4 +156,12 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt assertThat(link.getVariableNames()).contains("projection"); } } + + @Test // #1980 + public void considersIdConverterInLinkForItemResource() { + + Link link = entityLinks.linkForItemResource(Book.class, 7L).withSelfRel(); + + assertThat(link.getHref()).endsWith("/books/7-7-7-7-7-7-7"); + } } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinks.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinks.java index c148f7688..c2f08b523 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinks.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinks.java @@ -156,13 +156,26 @@ public class RepositoryEntityLinks extends AbstractEntityLinks { Assert.isInstanceOf(Serializable.class, id, "Id must be assignable to Serializable!"); ResourceMetadata metadata = mappings.getMetadataFor(type); + Link link = linkForItemResource(type, id).withRel(metadata.getItemResourceRel()); + + return Link.of(UriTemplate.of(link.getHref()).with(getProjectionVariable(type)).toString(), + metadata.getItemResourceRel()); + } + + /* + * (non-Javadoc) + * @see org.springframework.hateoas.server.core.AbstractEntityLinks#linkForItemResource(java.lang.Class, java.lang.Object) + */ + @Override + public LinkBuilder linkForItemResource(Class type, Object id) { + + Assert.isInstanceOf(Serializable.class, id, "Id must be assignable to Serializable!"); + String mappedId = idConverters.getPluginFor(type)// .orElse(DefaultIdConverter.INSTANCE)// .toRequestId((Serializable) id, type); - Link link = linkFor(type).slash(mappedId).withRel(metadata.getItemResourceRel()); - return Link.of(UriTemplate.of(link.getHref()).with(getProjectionVariable(type)).toString(), - metadata.getItemResourceRel()); + return linkFor(type).slash(mappedId); } /**