Skip to content

HttpMessageConverters not prepended with HAL Message Converter #134

Closed
@SirMaster

Description

@SirMaster

Hi,

On the startup of our application Spring instantiates certain processors like HttpEntityMethodProcessor and RequestResponseBodyMethodProcessor. These will be created with a reference to a list of HttpMessageConverters.

The list instance is set in the abstract class AbstractMessageConverterMethodArgumentResolver#messageConverters. But because some of the processors get created before HypermediaSupportBeanDefinitionRegistrar#registerBeanDefinitions is called it occurs that the replacing of the HttpMessageConverters will not have the proper effect.

I.e. HypermediaSupportBeanDefinitionRegistrar#registerBeanDefinitions does :

public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
    ....
    if (JACKSON2_PRESENT) {
        ...
        BeanDefinitionBuilder builder = rootBeanDefinition(Jackson2ModuleRegisteringBeanPostProcessor.class);
        ....
    }
    ....
}

Jackson2ModuleRegisteringBeanPostProcessor#postProcessAfterInitialization does

public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    ....
    if (bean instanceof RequestMappingHandlerAdapter) {
        RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean;
        adapter.setMessageConverters(potentiallyRegisterModule(adapter.getMessageConverters()));
    }
    ....
}

Jackson2ModuleRegisteringBeanPostProcessor#potentiallyRegisterModule does

private List<HttpMessageConverter<?>> potentiallyRegisterModule(List<HttpMessageConverter<?>> converters) {
    ....
    List<HttpMessageConverter<?>> result = new ArrayList<HttpMessageConverter<?>>(converters.size());
    result.add(halConverter);
    result.addAll(converters);
    return result;
}

The problem seems to be here in potentiallyRegisterModule, it returns a new List of HttpMessageConverts while there are still objects looking at the original list.

I tested this with :
Spring 3.2.5
Spring Hateoas 0.9.0.BUILD-SNAPSHOT

Many thx in advance for any input on this.

M.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions