Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Jan 20, 2010 · 9 comments
Assignees
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 20, 2010

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

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

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?

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 3, 2012

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.

@spring-projects-issues
Copy link
Collaborator Author

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>

@spring-projects-issues
Copy link
Collaborator Author

Burkhard Graves commented

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 4, 2014

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.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 13, 2014

Sébastien Deleuze commented

This issue it is duplicated by #11715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants