DATACMNS-1386 - Avoid strong type dependency to Jackson in SpringDataWebConfiguration.

We now avoid using a Lambda to provide a default ObjectMapper instance in the code that's reflectively guarded against Jackson not being present. The lambda causes a method to be generated for the class that will require ObjectMapper to be present on reflection inspection of that method. Switching to a method reference to ObjectMapper's constructor resolves that problem as the indirection via the additional, offending method is not needed.

Further reading: https://www.javabullets.com/how-lambdas-and-anonymous-inner-classesaic-work/
This commit is contained in:
Oliver Gierke
2018-09-07 11:58:58 +02:00
parent 3dacaf64d8
commit 8b6cc3af11
2 changed files with 20 additions and 3 deletions

View File

@@ -158,7 +158,7 @@ public class SpringDataWebConfiguration implements WebMvcConfigurer, BeanClassLo
if (ClassUtils.isPresent("com.jayway.jsonpath.DocumentContext", context.getClassLoader())
&& ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", context.getClassLoader())) {
ObjectMapper mapper = getUniqueBean(ObjectMapper.class, context, () -> new ObjectMapper());
ObjectMapper mapper = getUniqueBean(ObjectMapper.class, context, ObjectMapper::new);
ProjectingJackson2HttpMessageConverter converter = new ProjectingJackson2HttpMessageConverter(mapper);
converter.setBeanFactory(context);