Spring MVC4 Settings Use Fastjson as the JSON parser instead of Jackson

Source: Internet
Author: User

Regardless of performance, ease of use, feature support, Fastjson is far better than the default Jackson, so if the application often uses Ajax for data interaction, it is recommended to use Fastjson as the default parser, simply configure:

<mvc:annotation-driven>  <mvc:message-converters register-defaults= "true" >     <bean class= "Com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter" >         <property name= "Supportedmediatypes"  value= " Application/json "/>      <!--setting Fastjson features-->       <property name= "Features" >        <array>           <!--set a null value to output, Fastjson is off by default-->           <value>WriteMapNullValue</value>           <!--Set the output date using text, Fastjson default is long-->           <value>WriteDateUseDateFormat</value>         </array>      </property>    </bean>   </mvc:message-converters>  </mvc:annotation-driven>

Then the introduction of the Fastjson package is good.


Attached to the Spring MVC4 sample configuration file:

<?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:mvc= "http// Www.springframework.org/schema/mvc "    xsi:schemalocation=" http://www.springframework.org/ schema/beans        http://www.springframework.org/schema/beans/ Spring-beans.xsd        http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/ spring-context-4.1.xsd        http://www.springframework.org/schema/ Mvc        http://www.springframework.org/schema/mvc/ Spring-mvc-4.1.xsd "><!--Pack Scan--><context:componeNt-scan base-package= "com.rs"  /><!--data connection pool, used here c3p0--><bean id= "DataSource"   class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" >  <property name= "Driverclass"  value= "Com.mysql.jdbc.Driver"  />  <property name= "Jdbcurl"   Value= "Jdbc:mysql://x.x.x.x:3306/test"  />  <property name= "user"  value= "user"  />  <property name= "Password"  value= "PASS"  /></bean> <!- -Configure transaction manager--><bean id= "TransactionManager"  class= " Org.springframework.jdbc.datasource.DataSourceTransactionManager ">  <property name=" DataSource " ref=" DataSource " /></bean><!--use Fastjson as the JSON parser--&GT;&NBSP;&LT;MVC: Annotation-driven>  <mvc:message-converters register-defaults= "true" >     <bean class= "Com.alibaba.fastjson.support.spring.FastJsonHtTpmessageconverter ">        <property name=" Supportedmediatypes " value=" Application/json "/>      <property  Name= "Features" >        <array>           <value>WriteMapNullValue</value>           <value>WriteDateUseDateFormat</value>         </array>      </property>    </ bean>  </mvc:message-converters>  </mvc:annotation-driven><!-- Inject jdbctemplate--><bean id= "jdbc"  class= "Org.springframework.jdbc.core.JdbcTemplate" >   <property name= "DataSource"  ref= "DataSource"  /></bean><!--configuration View-->< Bean id= "Jspview"  class= "Org.sprIngframework.web.servlet.view.InternalResourceViewResolver ">  <property name=" prefix "  value= "/web-inf/views/"  />  <property name= "suffix"  value= ". JSP"  / ></bean><!--Configuring Interceptors--><mvc:interceptors>  <mvc:interceptor>     <!--block matching paths for HTML and do files-->    <mvc:mapping path= "/*/*.html"  / >    <mvc:mapping path= "/*/*.do"  />    <!-- Leave part of the request-->    <mvc:exclude-mapping path= "/home/login.html"  />     <mvc:exclude-mapping path= "/home/logout.html"  />    < !--a custom Interceptor-->   <bean class= "Com.nids.web.ActionInterceptor"  /> </ Mvc:interceptor></mvc:interceptors></beans>




This article is from the "Rabbit Nest" blog, please be sure to keep this source http://boytnt.blog.51cto.com/966121/1771390

Spring MVC4 Settings Use Fastjson as the JSON parser instead of Jackson

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.