I probably wrote this code expecting one day to be able to remove it. Maybe it's time now? All it would need would be a getter in Spring Framework.
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpMessageConverters.java#L151:
private void configurePartConverters(AllEncompassingFormHttpMessageConverter formConverter,
Collection<HttpMessageConverter<?>> converters) {
List<HttpMessageConverter<?>> partConverters = extractPartConverters(formConverter);
List<HttpMessageConverter<?>> combinedConverters = getCombinedConverters(converters, partConverters);
combinedConverters = postProcessPartConverters(combinedConverters);
formConverter.setPartConverters(combinedConverters);
}
@SuppressWarnings("unchecked")
private List<HttpMessageConverter<?>> extractPartConverters(FormHttpMessageConverter formConverter) {
Field field = ReflectionUtils.findField(FormHttpMessageConverter.class, "partConverters");
ReflectionUtils.makeAccessible(field);
return (List<HttpMessageConverter<?>>) ReflectionUtils.getField(field, formConverter);
}
Comment From: wilkinsona
If there was a getter in Framework we could certainly use it. Have you opened an issue asking for one?
There's a broader topic here in terms of the things that MVC configures by default and Boot then overwrites. For example, it spends time creating various ObjectMapper
instance in the message converters that Boot then replaces. In general, the work that HttpMessageConverters
does feels like something that could be reduced if Framework did less, or could be made to do less, by default. That feels like a Framework 6 topic. Perhaps we can get a new getter in 5.3 and at least reduce the use of reflection in the meantime?