Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7909401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:23:43+00:00 2026-06-03T12:23:43+00:00

I would like to replace the default objectMapper of the MappingJacksonHttpMessageConverter. I found a

  • 0

I would like to replace the default objectMapper of the MappingJacksonHttpMessageConverter.

I found a working solution but I am not happy about it:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
                       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                       http://www.springframework.org/schema/context
                       http://www.springframework.org/schema/context/spring-context-3.1.xsd
                       http://www.springframework.org/schema/util
                       http://www.springframework.org/schema/util/spring-util-2.0.xsd">

<!-- Scans the classpath of this application for @Components to deploy as beans -->
<context:component-scan base-package="org.mypackage.service"/>

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <property name="messageConverters">
        <list>
            <!--Adding the default message converters-->
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="writeAcceptCharset" value="false"/>
            </bean>
            <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>

            <!--Adding our custom JSON converter-->
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                <property name="objectMapper">
                    <util:constant static-field="org.mypackage.JsonUtils.MAPPER"/>
                </property>
            </bean>
        </list>
    </property>
</bean>

The solution initializes RequestMappingHandlerAdapter classes with my custom list of message converters.

I don’t like this solution because I needed to add the default message converters (which I copied from the org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter constructor).

Without adding the default converters – my controllers could handle only application/json requests and forgot how to handle other basic requests such as application/xml.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:23:46+00:00Added an answer on June 3, 2026 at 12:23 pm

    You can do it through code, without having to declare the RequestMappingHandlerAdapter bean and manually initialize all of those converters. You should write a BeanPostProcessor, like so:

    public class MyBeanPostProcessor implements BeanPostProcessor {
    
        public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
            return bean;
        }
    
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof AnnotationMethodHandlerAdapter) {
                AnnotationMethodHandlerAdapter adapter = (AnnotationMethodHandlerAdapter) bean;
                HttpMessageConverter<?>[] converters = adapter.getMessageConverters();
    
                for (HttpMessageConverter<?> converter : converters) {
                    if (converter instanceof MappingJacksonHttpMessageConverter) {
                        initConverter((MappingJacksonHttpMessageConverter) converter);
                    }
                }
            } else  if(bean instanceof MappingJacksonHttpMessageConverter){
                initConverter((MappingJacksonHttpMessageConverter) bean);
            }
            return bean;
        }
    
        private void initConverter(MappingJacksonHttpMessageConverter converter) {
                MappingJacksonHttpMessageConverter jsonConverter = (MappingJacksonHttpMessageConverter) converter;
                final ObjectMapper mapper = // get your mapper from wherever
                jsonConverter.setObjectMapper(mapper);
    
                /* here you can apply any other configuration you wish*/
         }
    }
    

    And define it as a bean:

    <bean class="my.package.MyBeanPostProcessor" id="myBeanPostProcessor" lazy-init="false"/>
    

    This way you edit exactly what actually interests you – the MappingJacksonHttpMessageConverter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to replace the default malloc at link time to use a
I would like to replace the default scrollbar of my site ( THIS page
I would like to know is there any possibility to replace default lock screen
I would like to replace the default logo in my NSIS installer (see image
I would like to replace the default GPS location provider on android phones with
I would like to replace only the group in parenthesis in this expression :
I would like to replace the entire header area in an NSIS installer with
I would like to replace drop down list (that has on change event that
I would like to replace the first character ' x ' with the number
I would like to replace blank spaces/white spaces in a string with commas. STR1=This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.