Skip to content

MappingJacksonHttpMessageConverter's ObjectMapper does not use ConversionService when binding JSON to JavaBean properties [SPR-6731] #11397

Closed

Description

@spring-projects-issues

Keith Donald opened SPR-6731 and commented

Noticed when using @RequestBody to bind an incoming JSON string to an Account JavaBean. I was expecting the binding process to respect format annotations such as @NumberFormat and @DateTimeFormat during string-to-propertyType conversion. However, this did not happen since it appears the MappingJacksonHttpMessageConverter is using the default Jackson ObjectMapper by default. For consistency, we should consider configuring Jackson to work with the ConversionService during its mapping process. This would allow format annotations like @NumberFormat and @DateTimeFormat to be respected.


Affects: 3.0 GA

Issue Links:

13 votes, 20 watchers

Activity

  1. spring-projects-issues commented on Jan 22, 2010

    @spring-projects-issues
    CollaboratorAuthor

    Keith Donald commented

    We have successfully plugged ConversionService into Jackson against Spring 3.0 here: https://src.springframework.org/svn/spring-samples/mvc-ajax/trunk

  2. spring-projects-issues commented on Mar 14, 2010

    @spring-projects-issues
    CollaboratorAuthor

    recoco zhang commented

    Hi, keith Donald, I have integrated Jackson to Spring 3.0 using your way. But I think it's not a Spring standard method. As I understand, it should be done by servlet config xml file. And it aroused another problem, I can't configure another conversionService such as dozer mapper together.

  3. spring-projects-issues commented on Jul 8, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Sebastien Tardif commented

    What is the workflow in the example? https://src.springframework.org/svn/spring-samples/mvc-ajax/trunk

    I don't see any mention of your custom mapping classes in the spring configuration xml file.

  4. spring-projects-issues commented on Dec 29, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Jet Ma commented

    Hi Keith, the sample's way to plug ConversionService into Jackson can't work in Spring 3.1.0 RELEASE. I realize since Spring 3.1.0 org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser does not allow us to inject a custom HttpMessageConverter(https://jira.springsource.org/browse/SPR-7091), and how can I do with the 3.1 version?

  5. spring-projects-issues commented on Jan 3, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    Jet, it is actually easier to provide a custom HttpMessageConverter in Spring 3.1. It's built into the MVC namespace as opposed to the mvc-ajax example which had to use a BeanPostProcessor to update the MappingJacksonHttpMessageConverter, see #11751.

  6. spring-projects-issues commented on Aug 29, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Andriy Godovanets commented

    So, if somebody wants to make mvc-ajax work for 3.1 spring version, he should:

    1. remove JacksonConversionServiceConfigurer.java
    2. update xsd schema version to 3.1 in servlet-context.xml
    3. change mvc:annotation-driven item in servlet-context.xml to:
    <mvc:annotation-driven>
       <mvc:message-converters>
           <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
               <property name="objectMapper">
                   <bean class="org.springframework.samples.mvc.ajax.json.ConversionServiceAwareObjectMapper" />
               </property>
           </bean>
       </mvc:message-converters>
    </mvc:annotation-driven>
    
  7. spring-projects-issues commented on Mar 10, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Burkhard Graves commented

    Any news concerning this task? Tips, examples, workarounds, other libs, ...? Appreciate any hints!

  8. spring-projects-issues commented on Nov 4, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    I think this need is now covered by the new support for Jackson MixIn Annotations available in the upcoming 4.1.2 release as part of #16758 and #16918.

    Please notice that it is now really easy to register them thanks to Jackson2ObjectMapperFactoryBean#mixIns and Jackson2ObjectMapperBuilder#mixIns().

    I plan to close this issue shortly unless someone think I should not.

  9. spring-projects-issues commented on Nov 13, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    This issue it is duplicated by #11715

  10. added
    type: enhancement
    has: votes-jira
    status: duplicate
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

has: votes-jirain: webstatus: duplicatetype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions