diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsJsonHttpMessageConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsJsonHttpMessageConverter.java index f0c016e37..590b4324c 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsJsonHttpMessageConverter.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsJsonHttpMessageConverter.java @@ -17,6 +17,7 @@ package org.springframework.data.rest.webmvc.alps; import java.lang.reflect.Type; import java.util.Arrays; +import java.util.Collections; import org.springframework.core.MethodParameter; import org.springframework.core.convert.converter.Converter; @@ -91,7 +92,8 @@ public class AlpsJsonHttpMessageConverter extends MappingJackson2HttpMessageConv Class> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { - return body instanceof RootResourceInformation ? converter.convert((RootResourceInformation) body) : body; + return body instanceof RootResourceInformation + ? Collections.singletonMap("alps", converter.convert((RootResourceInformation) body)) : body; } /* diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java index 525f747c3..2aff9d10b 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java @@ -92,8 +92,8 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL); client.follow(peopleLink, RestMediaTypes.ALPS_JSON)// - .andExpect(jsonPath("$.version").value("1.0"))// - .andExpect(jsonPath("$.descriptors[*].name", hasItems("people", "person"))); + .andExpect(jsonPath("$.alps.version").value("1.0"))// + .andExpect(jsonPath("$.alps.descriptors[*].name", hasItems("people", "person"))); } /** @@ -106,8 +106,8 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL); client.follow(peopleLink)// - .andExpect(jsonPath("$.version").value("1.0"))// - .andExpect(jsonPath("$.descriptors[*].name", hasItems("people", "person"))); + .andExpect(jsonPath("$.alps.version").value("1.0"))// + .andExpect(jsonPath("$.alps.descriptors[*].name", hasItems("people", "person"))); } @@ -122,11 +122,11 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio client.follow(itemsLink, RestMediaTypes.ALPS_JSON)// // Exposes standard property - .andExpect(jsonPath("$.descriptors[*].descriptors[*].name", hasItems("name"))) + .andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", hasItems("name"))) // Does not expose explicitly @JsonIgnored property - .andExpect(jsonPath("$.descriptors[*].descriptors[*].name", not(hasItems("owner")))) + .andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", not(hasItems("owner")))) // Does not expose properties pointing to non exposed types - .andExpect(jsonPath("$.descriptors[*].descriptors[*].name", not(hasItems("manager", "curator")))); + .andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", not(hasItems("manager", "curator")))); } /** @@ -141,7 +141,8 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio assertThat(itemsLink, is(notNullValue())); client.follow(itemsLink, RestMediaTypes.ALPS_JSON)// - .andExpect(jsonPath("$.descriptors[?(@.id == 'item-representation')][0].href", endsWith("/profile/items"))); + .andExpect( + jsonPath("$.alps.descriptors[?(@.id == 'item-representation')][0].href", endsWith("/profile/items"))); } /** @@ -153,7 +154,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio Link profileLink = client.discoverUnique("profile"); Link usersLink = client.discoverUnique(profileLink, "people", MediaType.ALL); - String jsonPath = "$."; // Root + String jsonPath = "$.alps."; // Root jsonPath += "descriptors[?(@.id == 'person-representation')]."; // Representation descriptor jsonPath += "descriptors[?(@.name == 'father')][0]."; // First father descriptor jsonPath += "rt"; // Return type @@ -174,6 +175,6 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio client.follow(itemsLink, RestMediaTypes.ALPS_JSON)// // Exposes identifier if configured to - .andExpect(jsonPath("$.descriptors[*].descriptors[*].name", hasItems("id", "name"))); + .andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", hasItems("id", "name"))); } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/Person.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/Person.java index 48967c4a4..f13f1a29c 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/Person.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/Person.java @@ -50,6 +50,7 @@ public class Person { private Person father; @Description("Timestamp this person object was created") private Date created; private int age, height, weight; + private Gender gender; public Person() {} @@ -146,4 +147,16 @@ public class Person { public void setWeight(int weight) { this.weight = weight; } + + public Gender getGender() { + return gender; + } + + public void setGender(Gender gender) { + this.gender = gender; + } + + public static enum Gender { + MALE, FEMALE, UNDEFINED; + } }