Custom ObjectMapper ignored after migration to Spring Boot 2











up vote
0
down vote

favorite












Before migrating to Spring Boot 2.1.0 I had the following ObjectMapper configured by extending WebMvcConfigurerAdapter working as expected.



@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

private static final ObjectMapper objectMapper = buildObjectMapper();

private static ObjectMapper buildObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configOverride(LocalDate.class).
setFormat(JsonFormat.Value.forPattern("yyyy-MM-dd"));
mapper.registerModule(new JavaTimeModule());
return mapper;
}

public static ObjectMapper getObjectMapper() {
return objectMapper;
}

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter(objectMapper)); // JSON converter
}
}


However after migrating I can see that setting PropertyNamingStrategy seems to have no effect, my application still expects the format of JSON fields to match the default (e.g. requires "bloodType" instead of "blood-type" as expected).



I don't think that there is any problem with the mapper itself as I use the static getObjectMapper to share the same instance with REST Assured via RestAssuredConfig and seems to be still behaving as expected, if I update my custom mapper to the default behavior (commenting setPropertyNamingStrategy) everything seem to work as expected.



EDIT 1



In fact my whole mapper is being ignored, I tried to change the LocalDate format and it also made no difference. Updating the title to reflect the problem better.










share|improve this question
























  • I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this. spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy Reference: docs.spring.io/spring-boot/docs/current/reference/html/…
    – Raheela Aslam
    Nov 19 at 6:28

















up vote
0
down vote

favorite












Before migrating to Spring Boot 2.1.0 I had the following ObjectMapper configured by extending WebMvcConfigurerAdapter working as expected.



@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

private static final ObjectMapper objectMapper = buildObjectMapper();

private static ObjectMapper buildObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configOverride(LocalDate.class).
setFormat(JsonFormat.Value.forPattern("yyyy-MM-dd"));
mapper.registerModule(new JavaTimeModule());
return mapper;
}

public static ObjectMapper getObjectMapper() {
return objectMapper;
}

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter(objectMapper)); // JSON converter
}
}


However after migrating I can see that setting PropertyNamingStrategy seems to have no effect, my application still expects the format of JSON fields to match the default (e.g. requires "bloodType" instead of "blood-type" as expected).



I don't think that there is any problem with the mapper itself as I use the static getObjectMapper to share the same instance with REST Assured via RestAssuredConfig and seems to be still behaving as expected, if I update my custom mapper to the default behavior (commenting setPropertyNamingStrategy) everything seem to work as expected.



EDIT 1



In fact my whole mapper is being ignored, I tried to change the LocalDate format and it also made no difference. Updating the title to reflect the problem better.










share|improve this question
























  • I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this. spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy Reference: docs.spring.io/spring-boot/docs/current/reference/html/…
    – Raheela Aslam
    Nov 19 at 6:28















up vote
0
down vote

favorite









up vote
0
down vote

favorite











Before migrating to Spring Boot 2.1.0 I had the following ObjectMapper configured by extending WebMvcConfigurerAdapter working as expected.



@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

private static final ObjectMapper objectMapper = buildObjectMapper();

private static ObjectMapper buildObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configOverride(LocalDate.class).
setFormat(JsonFormat.Value.forPattern("yyyy-MM-dd"));
mapper.registerModule(new JavaTimeModule());
return mapper;
}

public static ObjectMapper getObjectMapper() {
return objectMapper;
}

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter(objectMapper)); // JSON converter
}
}


However after migrating I can see that setting PropertyNamingStrategy seems to have no effect, my application still expects the format of JSON fields to match the default (e.g. requires "bloodType" instead of "blood-type" as expected).



I don't think that there is any problem with the mapper itself as I use the static getObjectMapper to share the same instance with REST Assured via RestAssuredConfig and seems to be still behaving as expected, if I update my custom mapper to the default behavior (commenting setPropertyNamingStrategy) everything seem to work as expected.



EDIT 1



In fact my whole mapper is being ignored, I tried to change the LocalDate format and it also made no difference. Updating the title to reflect the problem better.










share|improve this question















Before migrating to Spring Boot 2.1.0 I had the following ObjectMapper configured by extending WebMvcConfigurerAdapter working as expected.



@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

private static final ObjectMapper objectMapper = buildObjectMapper();

private static ObjectMapper buildObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configOverride(LocalDate.class).
setFormat(JsonFormat.Value.forPattern("yyyy-MM-dd"));
mapper.registerModule(new JavaTimeModule());
return mapper;
}

public static ObjectMapper getObjectMapper() {
return objectMapper;
}

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter(objectMapper)); // JSON converter
}
}


However after migrating I can see that setting PropertyNamingStrategy seems to have no effect, my application still expects the format of JSON fields to match the default (e.g. requires "bloodType" instead of "blood-type" as expected).



I don't think that there is any problem with the mapper itself as I use the static getObjectMapper to share the same instance with REST Assured via RestAssuredConfig and seems to be still behaving as expected, if I update my custom mapper to the default behavior (commenting setPropertyNamingStrategy) everything seem to work as expected.



EDIT 1



In fact my whole mapper is being ignored, I tried to change the LocalDate format and it also made no difference. Updating the title to reflect the problem better.







java spring-mvc spring-boot jackson






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 14:54

























asked Nov 19 at 6:12









Táizel Girão Martins

15




15












  • I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this. spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy Reference: docs.spring.io/spring-boot/docs/current/reference/html/…
    – Raheela Aslam
    Nov 19 at 6:28




















  • I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this. spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy Reference: docs.spring.io/spring-boot/docs/current/reference/html/…
    – Raheela Aslam
    Nov 19 at 6:28


















I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this. spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy Reference: docs.spring.io/spring-boot/docs/current/reference/html/…
– Raheela Aslam
Nov 19 at 6:28






I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this. spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy Reference: docs.spring.io/spring-boot/docs/current/reference/html/…
– Raheela Aslam
Nov 19 at 6:28














2 Answers
2






active

oldest

votes

















up vote
1
down vote













I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this.



spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy



Reference: docs.spring.io/spring-boot/docs/current/reference/html/…



OR:



   @Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
for (HttpMessageConverter<?> converter : converters) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter jsonMessageConverter = (MappingJackson2HttpMessageConverter) converter;
ObjectMapper objectMapper = jsonMessageConverter.getObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
break;
}
}
}





share|improve this answer























  • The problem can be seem on the JSON request parsed, at the REST controller the parsed object misses the fields that doesn't match the default format. Hibernate shouldn't be involved at this point, but maybe there is some Spring magic in place, in any case do you know how to set this property to have the KEBAB_CASE strategy so I could test your suggestion? For me this property should be used for something different, that's why I'm confused.
    – Táizel Girão Martins
    Nov 19 at 7:12












  • You can try my suggestion and provide your feed back. I think it will work .
    – Raheela Aslam
    Nov 19 at 7:36










  • I've tried your second suggestion, I replaced configureMessageConverters with your extendMessageConverters and still the same issue, however while doing that I decided to try to change my LocalDate format to see if it would have any difference and that this is also being ignored. I think it's a more general configuration issue as it seem that my custom ObjectMapper is completely ignored. I'm looking into the latest documentation to see what I'm doing wrong, I haven't found a big difference yet on the Spring Boot 2 documentation so far for those points.
    – Táizel Girão Martins
    Nov 20 at 10:13


















up vote
0
down vote



accepted










My problem was solved by adding the @EnableWebMvc annotation, which according to the documentation takes complete control of Spring MVC which is not what I wanted originally but at least makes sense. It's not clear for me why it was working before my migration to Spring Boot 2 and why extending the the Spring MVC behavior doesn't work anymore.



I would be grateful for one answer that would add a good explanation for this, and ideally would avoid the full override by @EnableWebMvc.



EDIT 1




Normally you would add @EnableWebMvc for a Spring MVC app, but Spring
Boot adds it automatically when it sees spring-webmvc on the
classpath.




Reference: https://spring.io/guides/gs/serving-web-content/



Unfortunately it's not a complete explanation for me as I can see spring-webmvc:5.1.2.RELEASE in my classpath.



I will mark this as answered considering that using @EnableWebMvc or configuring one @Bean for ObjectMapper are working as expected.



I will would still like to know why the @EnableWebMvc was needed, considering that according to the documentation it shouldn't.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369200%2fcustom-objectmapper-ignored-after-migration-to-spring-boot-2%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this.



    spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy



    Reference: docs.spring.io/spring-boot/docs/current/reference/html/…



    OR:



       @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    for (HttpMessageConverter<?> converter : converters) {
    if (converter instanceof MappingJackson2HttpMessageConverter) {
    MappingJackson2HttpMessageConverter jsonMessageConverter = (MappingJackson2HttpMessageConverter) converter;
    ObjectMapper objectMapper = jsonMessageConverter.getObjectMapper();
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
    break;
    }
    }
    }





    share|improve this answer























    • The problem can be seem on the JSON request parsed, at the REST controller the parsed object misses the fields that doesn't match the default format. Hibernate shouldn't be involved at this point, but maybe there is some Spring magic in place, in any case do you know how to set this property to have the KEBAB_CASE strategy so I could test your suggestion? For me this property should be used for something different, that's why I'm confused.
      – Táizel Girão Martins
      Nov 19 at 7:12












    • You can try my suggestion and provide your feed back. I think it will work .
      – Raheela Aslam
      Nov 19 at 7:36










    • I've tried your second suggestion, I replaced configureMessageConverters with your extendMessageConverters and still the same issue, however while doing that I decided to try to change my LocalDate format to see if it would have any difference and that this is also being ignored. I think it's a more general configuration issue as it seem that my custom ObjectMapper is completely ignored. I'm looking into the latest documentation to see what I'm doing wrong, I haven't found a big difference yet on the Spring Boot 2 documentation so far for those points.
      – Táizel Girão Martins
      Nov 20 at 10:13















    up vote
    1
    down vote













    I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this.



    spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy



    Reference: docs.spring.io/spring-boot/docs/current/reference/html/…



    OR:



       @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    for (HttpMessageConverter<?> converter : converters) {
    if (converter instanceof MappingJackson2HttpMessageConverter) {
    MappingJackson2HttpMessageConverter jsonMessageConverter = (MappingJackson2HttpMessageConverter) converter;
    ObjectMapper objectMapper = jsonMessageConverter.getObjectMapper();
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
    break;
    }
    }
    }





    share|improve this answer























    • The problem can be seem on the JSON request parsed, at the REST controller the parsed object misses the fields that doesn't match the default format. Hibernate shouldn't be involved at this point, but maybe there is some Spring magic in place, in any case do you know how to set this property to have the KEBAB_CASE strategy so I could test your suggestion? For me this property should be used for something different, that's why I'm confused.
      – Táizel Girão Martins
      Nov 19 at 7:12












    • You can try my suggestion and provide your feed back. I think it will work .
      – Raheela Aslam
      Nov 19 at 7:36










    • I've tried your second suggestion, I replaced configureMessageConverters with your extendMessageConverters and still the same issue, however while doing that I decided to try to change my LocalDate format to see if it would have any difference and that this is also being ignored. I think it's a more general configuration issue as it seem that my custom ObjectMapper is completely ignored. I'm looking into the latest documentation to see what I'm doing wrong, I haven't found a big difference yet on the Spring Boot 2 documentation so far for those points.
      – Táizel Girão Martins
      Nov 20 at 10:13













    up vote
    1
    down vote










    up vote
    1
    down vote









    I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this.



    spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy



    Reference: docs.spring.io/spring-boot/docs/current/reference/html/…



    OR:



       @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    for (HttpMessageConverter<?> converter : converters) {
    if (converter instanceof MappingJackson2HttpMessageConverter) {
    MappingJackson2HttpMessageConverter jsonMessageConverter = (MappingJackson2HttpMessageConverter) converter;
    ObjectMapper objectMapper = jsonMessageConverter.getObjectMapper();
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
    break;
    }
    }
    }





    share|improve this answer














    I think your mapper propertyNamingStrategy is not get by spring boot application its getting from hibernate propertyNamingStrategy you should try this.



    spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy



    Reference: docs.spring.io/spring-boot/docs/current/reference/html/…



    OR:



       @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    for (HttpMessageConverter<?> converter : converters) {
    if (converter instanceof MappingJackson2HttpMessageConverter) {
    MappingJackson2HttpMessageConverter jsonMessageConverter = (MappingJackson2HttpMessageConverter) converter;
    ObjectMapper objectMapper = jsonMessageConverter.getObjectMapper();
    mapper.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
    break;
    }
    }
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 19 at 8:13

























    answered Nov 19 at 6:44









    Raheela Aslam

    37010




    37010












    • The problem can be seem on the JSON request parsed, at the REST controller the parsed object misses the fields that doesn't match the default format. Hibernate shouldn't be involved at this point, but maybe there is some Spring magic in place, in any case do you know how to set this property to have the KEBAB_CASE strategy so I could test your suggestion? For me this property should be used for something different, that's why I'm confused.
      – Táizel Girão Martins
      Nov 19 at 7:12












    • You can try my suggestion and provide your feed back. I think it will work .
      – Raheela Aslam
      Nov 19 at 7:36










    • I've tried your second suggestion, I replaced configureMessageConverters with your extendMessageConverters and still the same issue, however while doing that I decided to try to change my LocalDate format to see if it would have any difference and that this is also being ignored. I think it's a more general configuration issue as it seem that my custom ObjectMapper is completely ignored. I'm looking into the latest documentation to see what I'm doing wrong, I haven't found a big difference yet on the Spring Boot 2 documentation so far for those points.
      – Táizel Girão Martins
      Nov 20 at 10:13


















    • The problem can be seem on the JSON request parsed, at the REST controller the parsed object misses the fields that doesn't match the default format. Hibernate shouldn't be involved at this point, but maybe there is some Spring magic in place, in any case do you know how to set this property to have the KEBAB_CASE strategy so I could test your suggestion? For me this property should be used for something different, that's why I'm confused.
      – Táizel Girão Martins
      Nov 19 at 7:12












    • You can try my suggestion and provide your feed back. I think it will work .
      – Raheela Aslam
      Nov 19 at 7:36










    • I've tried your second suggestion, I replaced configureMessageConverters with your extendMessageConverters and still the same issue, however while doing that I decided to try to change my LocalDate format to see if it would have any difference and that this is also being ignored. I think it's a more general configuration issue as it seem that my custom ObjectMapper is completely ignored. I'm looking into the latest documentation to see what I'm doing wrong, I haven't found a big difference yet on the Spring Boot 2 documentation so far for those points.
      – Táizel Girão Martins
      Nov 20 at 10:13
















    The problem can be seem on the JSON request parsed, at the REST controller the parsed object misses the fields that doesn't match the default format. Hibernate shouldn't be involved at this point, but maybe there is some Spring magic in place, in any case do you know how to set this property to have the KEBAB_CASE strategy so I could test your suggestion? For me this property should be used for something different, that's why I'm confused.
    – Táizel Girão Martins
    Nov 19 at 7:12






    The problem can be seem on the JSON request parsed, at the REST controller the parsed object misses the fields that doesn't match the default format. Hibernate shouldn't be involved at this point, but maybe there is some Spring magic in place, in any case do you know how to set this property to have the KEBAB_CASE strategy so I could test your suggestion? For me this property should be used for something different, that's why I'm confused.
    – Táizel Girão Martins
    Nov 19 at 7:12














    You can try my suggestion and provide your feed back. I think it will work .
    – Raheela Aslam
    Nov 19 at 7:36




    You can try my suggestion and provide your feed back. I think it will work .
    – Raheela Aslam
    Nov 19 at 7:36












    I've tried your second suggestion, I replaced configureMessageConverters with your extendMessageConverters and still the same issue, however while doing that I decided to try to change my LocalDate format to see if it would have any difference and that this is also being ignored. I think it's a more general configuration issue as it seem that my custom ObjectMapper is completely ignored. I'm looking into the latest documentation to see what I'm doing wrong, I haven't found a big difference yet on the Spring Boot 2 documentation so far for those points.
    – Táizel Girão Martins
    Nov 20 at 10:13




    I've tried your second suggestion, I replaced configureMessageConverters with your extendMessageConverters and still the same issue, however while doing that I decided to try to change my LocalDate format to see if it would have any difference and that this is also being ignored. I think it's a more general configuration issue as it seem that my custom ObjectMapper is completely ignored. I'm looking into the latest documentation to see what I'm doing wrong, I haven't found a big difference yet on the Spring Boot 2 documentation so far for those points.
    – Táizel Girão Martins
    Nov 20 at 10:13












    up vote
    0
    down vote



    accepted










    My problem was solved by adding the @EnableWebMvc annotation, which according to the documentation takes complete control of Spring MVC which is not what I wanted originally but at least makes sense. It's not clear for me why it was working before my migration to Spring Boot 2 and why extending the the Spring MVC behavior doesn't work anymore.



    I would be grateful for one answer that would add a good explanation for this, and ideally would avoid the full override by @EnableWebMvc.



    EDIT 1




    Normally you would add @EnableWebMvc for a Spring MVC app, but Spring
    Boot adds it automatically when it sees spring-webmvc on the
    classpath.




    Reference: https://spring.io/guides/gs/serving-web-content/



    Unfortunately it's not a complete explanation for me as I can see spring-webmvc:5.1.2.RELEASE in my classpath.



    I will mark this as answered considering that using @EnableWebMvc or configuring one @Bean for ObjectMapper are working as expected.



    I will would still like to know why the @EnableWebMvc was needed, considering that according to the documentation it shouldn't.






    share|improve this answer



























      up vote
      0
      down vote



      accepted










      My problem was solved by adding the @EnableWebMvc annotation, which according to the documentation takes complete control of Spring MVC which is not what I wanted originally but at least makes sense. It's not clear for me why it was working before my migration to Spring Boot 2 and why extending the the Spring MVC behavior doesn't work anymore.



      I would be grateful for one answer that would add a good explanation for this, and ideally would avoid the full override by @EnableWebMvc.



      EDIT 1




      Normally you would add @EnableWebMvc for a Spring MVC app, but Spring
      Boot adds it automatically when it sees spring-webmvc on the
      classpath.




      Reference: https://spring.io/guides/gs/serving-web-content/



      Unfortunately it's not a complete explanation for me as I can see spring-webmvc:5.1.2.RELEASE in my classpath.



      I will mark this as answered considering that using @EnableWebMvc or configuring one @Bean for ObjectMapper are working as expected.



      I will would still like to know why the @EnableWebMvc was needed, considering that according to the documentation it shouldn't.






      share|improve this answer

























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        My problem was solved by adding the @EnableWebMvc annotation, which according to the documentation takes complete control of Spring MVC which is not what I wanted originally but at least makes sense. It's not clear for me why it was working before my migration to Spring Boot 2 and why extending the the Spring MVC behavior doesn't work anymore.



        I would be grateful for one answer that would add a good explanation for this, and ideally would avoid the full override by @EnableWebMvc.



        EDIT 1




        Normally you would add @EnableWebMvc for a Spring MVC app, but Spring
        Boot adds it automatically when it sees spring-webmvc on the
        classpath.




        Reference: https://spring.io/guides/gs/serving-web-content/



        Unfortunately it's not a complete explanation for me as I can see spring-webmvc:5.1.2.RELEASE in my classpath.



        I will mark this as answered considering that using @EnableWebMvc or configuring one @Bean for ObjectMapper are working as expected.



        I will would still like to know why the @EnableWebMvc was needed, considering that according to the documentation it shouldn't.






        share|improve this answer














        My problem was solved by adding the @EnableWebMvc annotation, which according to the documentation takes complete control of Spring MVC which is not what I wanted originally but at least makes sense. It's not clear for me why it was working before my migration to Spring Boot 2 and why extending the the Spring MVC behavior doesn't work anymore.



        I would be grateful for one answer that would add a good explanation for this, and ideally would avoid the full override by @EnableWebMvc.



        EDIT 1




        Normally you would add @EnableWebMvc for a Spring MVC app, but Spring
        Boot adds it automatically when it sees spring-webmvc on the
        classpath.




        Reference: https://spring.io/guides/gs/serving-web-content/



        Unfortunately it's not a complete explanation for me as I can see spring-webmvc:5.1.2.RELEASE in my classpath.



        I will mark this as answered considering that using @EnableWebMvc or configuring one @Bean for ObjectMapper are working as expected.



        I will would still like to know why the @EnableWebMvc was needed, considering that according to the documentation it shouldn't.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 at 12:02

























        answered Nov 19 at 12:59









        Táizel Girão Martins

        15




        15






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369200%2fcustom-objectmapper-ignored-after-migration-to-spring-boot-2%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'