Refine BackgroundPreinitializer Jackson initialization

AllEncompassingFormHttpMessageConverter already initializes
Jackson ObjectMapper. This commit updates BackgroundPreinitializer
in order to not run JacksonInitializer when
MessageConverterInitializer already takes care of initializing
ObjectMapper.

See gh-33220
pull/33276/head
Sébastien Deleuze 2 years ago committed by Phillip Webb
parent a650361f1d
commit bdac416a62

@ -34,6 +34,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.util.ClassUtils;
/** /**
* {@link ApplicationListener} to trigger early initialization in a background thread of * {@link ApplicationListener} to trigger early initialization in a background thread of
@ -100,8 +101,14 @@ public class BackgroundPreinitializer implements ApplicationListener<SpringAppli
public void run() { public void run() {
runSafely(new ConversionServiceInitializer()); runSafely(new ConversionServiceInitializer());
runSafely(new ValidationInitializer()); runSafely(new ValidationInitializer());
runSafely(new MessageConverterInitializer()); if (ClassUtils.isPresent(
runSafely(new JacksonInitializer()); "org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter",
BackgroundPreinitializer.class.getClassLoader())) {
runSafely(new MessageConverterInitializer());
}
else {
runSafely(new JacksonInitializer());
}
runSafely(new CharsetInitializer()); runSafely(new CharsetInitializer());
preinitializationComplete.countDown(); preinitializationComplete.countDown();
} }

Loading…
Cancel
Save