diff --git a/pom.xml b/pom.xml index af1d6c1ed..acbe6c228 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ 4.0.0.BUILD-SNAPSHOT 2.1.0.BUILD-SNAPSHOT 2.1.0.BUILD-SNAPSHOT + 0.25.0.BUILD-SNAPSHOT 4.3.10.Final 1.1.0 diff --git a/spring-data-rest-hal-browser/src/test/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowserIntegrationTests.java b/spring-data-rest-hal-browser/src/test/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowserIntegrationTests.java index 48b79eafd..9f3536c72 100755 --- a/spring-data-rest-hal-browser/src/test/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowserIntegrationTests.java +++ b/spring-data-rest-hal-browser/src/test/java/org/springframework/data/rest/webmvc/halbrowser/HalBrowserIntegrationTests.java @@ -28,8 +28,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.ConversionService; -import org.springframework.data.rest.core.config.RepositoryRestConfiguration; -import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter; +import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer; import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; import org.springframework.hateoas.MediaTypes; import org.springframework.http.HttpHeaders; @@ -66,15 +65,8 @@ public TestConfiguration(ApplicationContext context, ObjectFactory config.setBasePath(BASE_PATH)); } } diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java index 13ce55836..4f8dd6c0a 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java @@ -69,7 +69,7 @@ static class Config { @Bean public LinkDiscoverer alpsLinkDiscoverer() { - return new JsonPathLinkDiscoverer("$.descriptors[?(@.name == '%s')].href", + return new JsonPathLinkDiscoverer("$.descriptor[?(@.name == '%s')].href", MediaType.valueOf("application/alps+json")); } @@ -101,7 +101,7 @@ public void exposesAlpsCollectionResources() throws Exception { client.follow(peopleLink, RestMediaTypes.ALPS_JSON)// .andExpect(jsonPath("$.alps.version").value("1.0"))// - .andExpect(jsonPath("$.alps.descriptors[*].name", hasItems("people", "person"))); + .andExpect(jsonPath("$.alps.descriptor[*].name", hasItems("people", "person"))); } @Test // DATAREST-638 @@ -112,7 +112,7 @@ public void verifyThatAlpsIsDefaultProfileFormat() throws Exception { client.follow(peopleLink)// .andExpect(jsonPath("$.alps.version").value("1.0"))// - .andExpect(jsonPath("$.alps.descriptors[*].name", hasItems("people", "person"))); + .andExpect(jsonPath("$.alps.descriptor[*].name", hasItems("people", "person"))); } @@ -124,11 +124,11 @@ public void verifyThatAttributesIgnoredDontAppearInAlps() throws Exception { client.follow(itemsLink, RestMediaTypes.ALPS_JSON)// // Exposes standard property - .andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", hasItems("name"))) + .andExpect(jsonPath("$.alps.descriptor[*].descriptor[*].name", hasItems("name"))) // Does not expose explicitly @JsonIgnored property - .andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", not(hasItems("owner")))) + .andExpect(jsonPath("$.alps.descriptor[*].descriptor[*].name", not(hasItems("owner")))) // Does not expose properties pointing to non exposed types - .andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", not(hasItems("manager", "curator")))); + .andExpect(jsonPath("$.alps.descriptor[*].descriptor[*].name", not(hasItems("manager", "curator")))); } @Test // DATAREST-494 @@ -140,7 +140,7 @@ public void linksToJsonSchemaFromRepresentationDescriptor() throws Exception { assertThat(itemsLink).isNotNull(); String result = client.follow(itemsLink, RestMediaTypes.ALPS_JSON).andReturn().getResponse().getContentAsString(); - String href = JsonPath. read(result, "$.alps.descriptors[?(@.id == 'item-representation')].href").get(0) + String href = JsonPath. read(result, "$.alps.descriptor[?(@.id == 'item-representation')].href").get(0) .toString(); assertThat(href, endsWith("/profile/items")); @@ -153,8 +153,8 @@ public void referenceToAssociatedEntityDesciptorPointsToRepresentationDescriptor Link usersLink = client.discoverUnique(profileLink, "people", MediaType.ALL); String jsonPath = "$.alps."; // Root - jsonPath += "descriptors[?(@.id == 'person-representation')]."; // Representation descriptor - jsonPath += "descriptors[?(@.name == 'father')]."; // First father descriptor + jsonPath += "descriptor[?(@.id == 'person-representation')]."; // Representation descriptor + jsonPath += "descriptor[?(@.name == 'father')]."; // First father descriptor jsonPath += "rt"; // Return type String result = client.follow(usersLink, RestMediaTypes.ALPS_JSON).andReturn().getResponse().getContentAsString(); @@ -171,7 +171,7 @@ public void onlyExposesIdAttributesWhenExposedInTheConfiguration() throws Except client.follow(itemsLink, RestMediaTypes.ALPS_JSON)// // Exposes identifier if configured to - .andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", hasItems("id", "name"))); + .andExpect(jsonPath("$.alps.descriptor[*].descriptor[*].name", hasItems("id", "name"))); } @Test // DATAREST-683 @@ -186,7 +186,7 @@ public void enumValueListingsAreTranslatedIfEnabled() throws Exception { String value = JsonPath . read(result, - "$.alps.descriptors[?(@.id == 'person-representation')].descriptors[?(@.name == 'gender')].doc.value") + "$.alps.descriptor[?(@.id == 'person-representation')].descriptor[?(@.name == 'gender')].doc.value") .get(0).toString(); assertThat(value).isEqualTo("Male, Female, Undefined"); @@ -202,7 +202,7 @@ public void alpsCanHandleGroovyDomainObjects() throws Exception { String name = JsonPath . read(result, - "$.alps.descriptors[?(@.id == 'simulatedGroovyDomainClass-representation')].descriptors[0].name") + "$.alps.descriptor[?(@.id == 'simulatedGroovyDomainClass-representation')].descriptor[0].name") .get(0).toString(); assertThat(name).isEqualTo("name"); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java index 32bdf4cc8..f58ee3cc2 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java @@ -26,11 +26,9 @@ import javax.validation.constraints.NotNull; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -41,9 +39,16 @@ import org.springframework.data.rest.webmvc.PersistentEntityResource; import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; import org.springframework.hateoas.Link; +import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; +import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.PropertyAccessor; @@ -69,11 +74,18 @@ static class Config { @Autowired ApplicationContext beanFactory; @Autowired JpaMetamodelMappingContext mappingContext; @Autowired AirportRepository repository; - @Autowired @Qualifier("halObjectMapper") ObjectMapper mapper; + + ObjectMapper mapper; @Before public void setUp() { - mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + + this.mapper = beanFactory // + .getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class) // + .getObjectMapper() // + .copy(); + + this.mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); } @Test // DATAREST-262 @@ -87,9 +99,13 @@ public void deserializesNestedAssociation() throws Exception { } @Test // DATAREST-262 - @Ignore public void serializesLinksToNestedAssociations() throws Exception { + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addHeader(HttpHeaders.ACCEPT, MediaTypes.HAL_JSON_VALUE); + RequestAttributes attributes = new ServletRequestAttributes(request); + RequestContextHolder.setRequestAttributes(attributes); + Airport first = new Airport(); first.id = 1L; @@ -112,9 +128,9 @@ public void serializesLinksToNestedAssociations() throws Exception { String result = mapper.writeValueAsString(resource); - assertThat(JsonPath. read(result, "$_links.self")).isNotNull(); - assertThat(JsonPath. read(result, "$_links.airport")).isNotNull(); - assertThat(JsonPath. read(result, "$_links.originOrDestinationAirport")).isNotNull(); + assertThat(JsonPath. read(result, "$._links.self")).isNotNull(); + assertThat(JsonPath. read(result, "$._links.originOrDestinationAirport")).isNotNull(); + assertThat(JsonPath. read(result, "$.orgOrDstFlightPart._links.airport")).isNotNull(); } public interface AircraftMovementRepository extends CrudRepository { diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/Jackson2DatatypeHelperIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/Jackson2DatatypeHelperIntegrationTests.java index 1a536bc00..50fec4a2a 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/Jackson2DatatypeHelperIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/Jackson2DatatypeHelperIntegrationTests.java @@ -23,6 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.PersistentPropertyAccessor; @@ -33,6 +34,7 @@ import org.springframework.data.rest.webmvc.jpa.OrderRepository; import org.springframework.data.rest.webmvc.jpa.Person; import org.springframework.data.rest.webmvc.jpa.PersonRepository; +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @@ -50,18 +52,22 @@ public class Jackson2DatatypeHelperIntegrationTests { @Autowired PersistentEntities entities; - @Autowired ObjectMapper objectMapper; + @Autowired ApplicationContext context; @Autowired PersonRepository people; @Autowired OrderRepository orders; @Autowired EntityManager em; + ObjectMapper objectMapper; + Order order; @Before public void setUp() { this.order = orders.save(new Order(people.save(new Person("Dave", "Matthews")))); + this.objectMapper = context.getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class) + .getObjectMapper(); // Reset JPA to make sure the query returns a result with proxy references em.flush(); diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceAssemblerIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceAssemblerIntegrationTests.java index 3ba22a857..9754410dd 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceAssemblerIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceAssemblerIntegrationTests.java @@ -25,7 +25,6 @@ import org.junit.Test; import org.mockito.internal.stubbing.answers.ReturnsArgumentAt; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.mapping.context.PersistentEntities; import org.springframework.data.rest.core.support.DefaultSelfLinkProvider; import org.springframework.data.rest.core.support.EntityLookup; @@ -39,8 +38,6 @@ import org.springframework.hateoas.Links; import org.springframework.test.context.ContextConfiguration; -import com.fasterxml.jackson.databind.ObjectMapper; - /** * Integration tests for {@link PersistentEntityResourceAssembler}. * @@ -51,7 +48,6 @@ public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractC @Autowired PersistentEntities entities; @Autowired EntityLinks entityLinks; - @Autowired @Qualifier("objectMapper") ObjectMapper objectMapper; @Autowired Associations associations; @Test // DATAREST-609 diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java index c8d1168cd..30e7bb3bc 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java @@ -42,7 +42,7 @@ import org.springframework.data.rest.tests.mongodb.User.EmailAddress; import org.springframework.data.rest.tests.mongodb.User.TypeWithPattern; import org.springframework.data.rest.tests.mongodb.groovy.SimulatedGroovyDomainClass; -import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter; +import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer; import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.ValueTypeSchemaPropertyCustomizerFactory; import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverterUnitTests.TestConfiguration; @@ -66,12 +66,13 @@ public class PersistentEntityToJsonSchemaConverterUnitTests { @Autowired @Qualifier("resourceDescriptionMessageSourceAccessor") MessageSourceAccessor accessor; @Autowired RepositoryRestConfiguration configuration; @Autowired PersistentEntities entities; - @Autowired @Qualifier("objectMapper") ObjectMapper objectMapper; @Autowired Associations associations; + ObjectMapper objectMapper = new ObjectMapper(); + @Configuration @Import(RepositoryRestMvcConfiguration.class) - static class TestConfiguration extends RepositoryRestConfigurerAdapter { + static class TestConfiguration implements RepositoryRestConfigurer { @Override public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java index 132b7ebc8..c9758cb3c 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.java @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.springframework.beans.factory.BeanClassLoaderAware; @@ -29,6 +30,7 @@ import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.ObjectFactory; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.config.PropertiesFactoryBean; @@ -117,6 +119,7 @@ import org.springframework.data.rest.webmvc.support.PagingAndSortingTemplateVariables; import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks; import org.springframework.data.util.AnnotatedTypeScanner; +import org.springframework.data.util.Lazy; import org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver; import org.springframework.data.web.HateoasSortHandlerMethodArgumentResolver; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; @@ -132,6 +135,7 @@ import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; import org.springframework.hateoas.core.EvoInflectorRelProvider; import org.springframework.hateoas.hal.CurieProvider; +import org.springframework.hateoas.hal.HalConfiguration; import org.springframework.hateoas.hal.Jackson2HalModule; import org.springframework.hateoas.hal.Jackson2HalModule.HalHandlerInstantiator; import org.springframework.hateoas.mvc.ResourceProcessorInvoker; @@ -189,15 +193,32 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon @Autowired(required = false) List configurers = Collections.emptyList(); @Autowired(required = false) List> lookups = Collections.emptyList(); - @Autowired(required = false) RelProvider relProvider; - @Autowired(required = false) CurieProvider curieProvider; + @Autowired Optional relProvider; + @Autowired Optional curieProvider; + @Autowired Optional halConfiguration; + @Autowired ObjectProvider objectMapper; + + private final Lazy mapper; private RepositoryRestConfigurerDelegate configurerDelegate; private ClassLoader beanClassLoader; public RepositoryRestMvcConfiguration(ApplicationContext context, @Qualifier("mvcConversionService") ObjectFactory conversionService) { + super(context, conversionService); + + this.mapper = Lazy.of(() -> { + + Jdk8Module jdk8Module = new Jdk8Module(); + jdk8Module.configureAbsentsAsNulls(true); + + ObjectMapper mapper = basicObjectMapper(); + mapper.registerModule(persistentEntityJackson2Module()); + mapper.registerModule(jdk8Module); + + return mapper; + }); } /* @@ -461,17 +482,8 @@ public MessageSourceAccessor resourceDescriptionMessageSourceAccessor() { * * @return */ - @Bean public ObjectMapper objectMapper() { - - Jdk8Module jdk8Module = new Jdk8Module(); - jdk8Module.configureAbsentsAsNulls(true); - - ObjectMapper mapper = basicObjectMapper(); - mapper.registerModule(persistentEntityJackson2Module()); - mapper.registerModule(jdk8Module); - - return mapper; + return mapper.get(); } /** @@ -529,13 +541,13 @@ public TypeConstrainedMappingJackson2HttpMessageConverter halJacksonHttpMessageC return converter; } - @Bean public ObjectMapper halObjectMapper() { - RelProvider defaultedRelProvider = this.relProvider != null ? this.relProvider : new EvoInflectorRelProvider(); + RelProvider defaultedRelProvider = this.relProvider.orElseGet(() -> new EvoInflectorRelProvider()); + HalConfiguration halConfiguration = this.halConfiguration.orElseGet(() -> new HalConfiguration()); - HalHandlerInstantiator instantiator = new HalHandlerInstantiator(defaultedRelProvider, curieProvider, - resourceDescriptionMessageSourceAccessor(), applicationContext.getAutowireCapableBeanFactory()); + HalHandlerInstantiator instantiator = new HalHandlerInstantiator(defaultedRelProvider, curieProvider.orElse(null), + resourceDescriptionMessageSourceAccessor(), halConfiguration); ObjectMapper mapper = basicObjectMapper(); mapper.registerModule(persistentEntityJackson2Module()); @@ -849,7 +861,8 @@ protected List defaultMethodArgumentResolvers() { protected ObjectMapper basicObjectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); + ObjectMapper mapper = this.objectMapper.getIfAvailable(); + ObjectMapper objectMapper = mapper == null ? new ObjectMapper() : mapper.copy(); objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java index 76573963e..11cf0fd00 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java @@ -17,14 +17,15 @@ import static org.assertj.core.api.Assertions.*; -import javax.naming.Name; -import javax.naming.ldap.LdapName; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.TimeZone; +import javax.naming.Name; +import javax.naming.ldap.LdapName; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -53,6 +54,7 @@ import org.springframework.hateoas.core.DefaultRelProvider; import org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.MultiValueMap; @@ -96,9 +98,7 @@ public void assertBeansBeingSetUp() throws Exception { context.getBean(PageableHandlerMethodArgumentResolver.class); // Verify HAL setup - context.getBean("halJacksonHttpMessageConverter", HttpMessageConverter.class); - ObjectMapper mapper = context.getBean("halObjectMapper", ObjectMapper.class); - mapper.writeValueAsString(new RepositoryLinksResource()); + getObjectMapper().writeValueAsString(new RepositoryLinksResource()); } @Test // DATAREST-271 @@ -125,7 +125,7 @@ public void objectMapperRendersDatesInIsoByDefault() throws Exception { Sample sample = new Sample(); sample.date = new Date(); - ObjectMapper mapper = context.getBean("objectMapper", ObjectMapper.class); + ObjectMapper mapper = getObjectMapper(); DateFormatter formatter = new DateFormatter(); formatter.setPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); @@ -206,6 +206,13 @@ public void defaultsEncodingForMessageSourceToUtfEight() { assertThat((String) ReflectionTestUtils.getField(messageSource, "defaultEncoding")).isEqualTo("UTF-8"); } + private static ObjectMapper getObjectMapper() { + + AbstractJackson2HttpMessageConverter converter = context.getBean("halJacksonHttpMessageConverter", + AbstractJackson2HttpMessageConverter.class); + return converter.getObjectMapper(); + } + @Configuration @Import(RepositoryRestMvcConfiguration.class) static class ExtendingConfiguration {