Using Fastjson in Spring

Source: Internet
Author: User

JSON parsing is used in springboot, but we prefer to use some of the things in Fastjson, how to overwrite 1. The first way to inherit the parent class overrides
Package Com.ithuan;import Java.util.list;import Org.springframework.boot.springapplication;import Org.springframework.boot.autoconfigure.springbootapplication;import Org.springframework.http.converter.httpmessageconverter;import Org.springframework.web.servlet.config.annotation.webmvcconfigureradapter;import Com.alibaba.fastjson.serializer.serializerfeature;import Com.alibaba.fastjson.support.config.FastJsonConfig; Import com.alibaba.fastjson.support.spring.fastjsonhttpmessageconverter;/** * Hello world! * */@SpringBootApplicationpublic class APP extends webmvcconfigureradapter{@Overridepublic void Configuremessageconverters (list2. The second way to use the @bean label
/** * Here we use the @Bean to inject Fastjsonhttpmessageconvert * @return * */@Beanpublic Httpmessageconverters Fastjsonhttpmessageconverters () {///1, the object that needs to first define a convert conversion message; Fastjsonhttpmessageconverter fastconverter = new Fastjsonhttpmessageconverter ();//2, add Fastjson configuration information, For example: whether to format the returned JSON data; Fastjsonconfig fastjsonconfig = new Fastjsonconfig (); Fastjsonconfig.setserializerfeatures ( Serializerfeature.prettyformat);//3, add configuration information in convert. Fastconverter.setfastjsonconfig (fastjsonconfig); httpmessageconverter<?> converter = Fastconverter;return new Httpmessageconverters (converter);}
3. Use Cases
1. Some annotation//date formats for Fastjson can be used in entity classes @jsonfield (format= "Yyyy-mm-dd HH:mm:ss") Private date cretetime;//indicates that @jsonfield is not displayed ( Serialize=false)//2. The Fastjson style is used when the page is displayed.

Using Fastjson in Spring

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.