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 Cases1. 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