当前位置: 首页 > news >正文

东莞网上推广找谁网站优化推广软件

东莞网上推广找谁,网站优化推广软件,装饰公司网站,网店怎么运营推广在json对象转换方面,springboot默认使用的是MappingJackson2HttpMessageConverter。常规需求,在工程中使用阿里的FastJson作为json对象的转换器。 FastJson SerializerFeatures WriteNullListAsEmpty :List字段如果为null,输出为[],而非nu…

在json对象转换方面,springboot默认使用的是MappingJackson2HttpMessageConverter。常规需求,在工程中使用阿里的FastJson作为json对象的转换器。

FastJson SerializerFeatures

WriteNullListAsEmpty  :List字段如果为null,输出为[],而非null
WriteNullStringAsEmpty : 字符类型字段如果为null,输出为"",而非null
DisableCircularReferenceDetect :消除对同一对象循环引用的问题,默认为false(如果不配置有可能会进入死循环)
WriteNullBooleanAsFalse:Boolean字段如果为null,输出为false,而非null
WriteMapNullValue:是否输出值为null的字段,默认为false。

public enum SerializerFeature {QuoteFieldNames,UseSingleQuotes,WriteMapNullValue,WriteEnumUsingToString,WriteEnumUsingName,UseISO8601DateFormat,WriteNullListAsEmpty,WriteNullStringAsEmpty,WriteNullNumberAsZero,WriteNullBooleanAsFalse,SkipTransientField,SortField,/** @deprecated */@DeprecatedWriteTabAsSpecial,PrettyFormat,WriteClassName,DisableCircularReferenceDetect,WriteSlashAsSpecial,BrowserCompatible,WriteDateUseDateFormat,NotWriteRootClassName,/** @deprecated */DisableCheckSpecialChar,BeanToArray,WriteNonStringKeyAsString,NotWriteDefaultValue,BrowserSecure,IgnoreNonFieldGetter,WriteNonStringValueAsString,IgnoreErrorGetter,WriteBigDecimalAsPlain,MapSortField;
}

使用FastJson,有两种常规操作。

一、注入bean的方式,这种方法加入的转换器排序是第一位

package com.gaoshan.verification.config;import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.List;@Configuration
public class WebMvcConfigurerConfig implements WebMvcConfigurer {@Overridepublic void extendMessageConverters(List<HttpMessageConverter<?>> converters) {for (HttpMessageConverter<?> messageConverter : converters) {System.out.println("======================"+messageConverter);}}
}
package com.gaoshan.verification.config;import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;import java.util.ArrayList;
import java.util.List;@Configuration
public class MessageConvertConfig {@Beanpublic HttpMessageConverters fastJsonHttpMessageConverters() {FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();FastJsonConfig fastJsonConfig = new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteBigDecimalAsPlain,SerializerFeature.WriteMapNullValue);fastConverter.setFastJsonConfig(fastJsonConfig);List<MediaType> supportedMediaTypes = new ArrayList<>();supportedMediaTypes.add(MediaType.APPLICATION_JSON);fastConverter.setSupportedMediaTypes(supportedMediaTypes);return new HttpMessageConverters(fastConverter);}
}

======================com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter@2c5708e7
======================org.springframework.http.converter.ByteArrayHttpMessageConverter@4ffa078d
======================org.springframework.http.converter.StringHttpMessageConverter@4e26564d
======================org.springframework.http.converter.ResourceHttpMessageConverter@42238078
======================org.springframework.http.converter.ResourceRegionHttpMessageConverter@5627b8eb
======================org.springframework.http.converter.xml.SourceHttpMessageConverter@49fe0bcd
======================org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter@3516b881
======================org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@6be8ce1b
======================org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter@e3c36d

二、实现WebMvcConfigurer接口,这种方法加入的转换器排序是最后一位

package com.gaoshan.verification.config;import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.ArrayList;
import java.util.List;@Configuration
public class WebMvcConfigurerConfig implements WebMvcConfigurer {@Overridepublic void extendMessageConverters(List<HttpMessageConverter<?>> converters) {for (HttpMessageConverter<?> messageConverter : converters) {System.out.println("======================"+messageConverter);}}@Overridepublic void configureMessageConverters(List<HttpMessageConverter<?>> converters) {FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();FastJsonConfig fastJsonConfig = new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteBigDecimalAsPlain,SerializerFeature.WriteMapNullValue);fastConverter.setFastJsonConfig(fastJsonConfig);List<MediaType> supportedMediaTypes = new ArrayList<>();supportedMediaTypes.add(MediaType.APPLICATION_JSON);fastConverter.setSupportedMediaTypes(supportedMediaTypes);converters.add(fastConverter);}
}

 ======================org.springframework.http.converter.ByteArrayHttpMessageConverter@71f29d91
======================org.springframework.http.converter.StringHttpMessageConverter@6785df10
======================org.springframework.http.converter.StringHttpMessageConverter@6143b2b1
======================org.springframework.http.converter.ResourceHttpMessageConverter@a63643e
======================org.springframework.http.converter.ResourceRegionHttpMessageConverter@43294e9b
======================org.springframework.http.converter.xml.SourceHttpMessageConverter@26d24d7a
======================org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter@5a78b52b
======================org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@144440f5
======================org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@4bab78ce
======================org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter@42ffbab6
======================com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter@7672960e

注意:

1、可以两种方式同时使用,这样可以达到目的,在转换器列表的头尾,都会出现FastJsonHttpMessageConverter

======================com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter@2c5708e7
======================org.springframework.http.converter.ByteArrayHttpMessageConverter@4ffa078d
======================org.springframework.http.converter.StringHttpMessageConverter@4e26564d
======================org.springframework.http.converter.ResourceHttpMessageConverter@42238078
======================org.springframework.http.converter.ResourceRegionHttpMessageConverter@5627b8eb
======================org.springframework.http.converter.xml.SourceHttpMessageConverter@49fe0bcd
======================org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter@3516b881
======================org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@6be8ce1b
======================org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter@e3c36d
======================com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter@397a10df

 

2、不要乱加 @EnableWebMvc标签,这个标签会导致添加自定义消息转换器失败。因为时间问题,目前还不清楚具体原因

  • 针对方案一,启动类或任意配置类,加了@EnableWebMvc后,导致自定义的转换器没有出现在集合内,即添加自定义转换器失败
package com.gaoshan.verification.config;import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.List;@Configuration
@EnableWebMvc
public class WebMvcConfigurerConfig implements WebMvcConfigurer {@Overridepublic void extendMessageConverters(List<HttpMessageConverter<?>> converters) {for (HttpMessageConverter<?> messageConverter : converters) {System.out.println("======================"+messageConverter);}}
}
package com.gaoshan.verification.config;import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;import java.util.ArrayList;
import java.util.List;@Configuration
public class MessageConvertConfig {@Beanpublic HttpMessageConverters fastJsonHttpMessageConverters() {FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();FastJsonConfig fastJsonConfig = new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteBigDecimalAsPlain,SerializerFeature.WriteMapNullValue);fastConverter.setFastJsonConfig(fastJsonConfig);List<MediaType> supportedMediaTypes = new ArrayList<>();supportedMediaTypes.add(MediaType.APPLICATION_JSON);fastConverter.setSupportedMediaTypes(supportedMediaTypes);return new HttpMessageConverters(fastConverter);}
}

 ======================org.springframework.http.converter.ByteArrayHttpMessageConverter@42238078
======================org.springframework.http.converter.StringHttpMessageConverter@5627b8eb
======================org.springframework.http.converter.ResourceHttpMessageConverter@49fe0bcd
======================org.springframework.http.converter.ResourceRegionHttpMessageConverter@3516b881
======================org.springframework.http.converter.xml.SourceHttpMessageConverter@6be8ce1b
======================org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter@e3c36d
======================org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter@397a10df
======================org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@39a865c1

  • 针对方案二,启动类或任意配置类,加了@EnableWebMvc后,导致集合内仅有自定义转换器
package com.gaoshan.verification.config;import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.ArrayList;
import java.util.List;@Configuration
@EnableWebMvc
public class WebMvcConfigurerConfig implements WebMvcConfigurer {@Overridepublic void extendMessageConverters(List<HttpMessageConverter<?>> converters) {for (HttpMessageConverter<?> messageConverter : converters) {System.out.println("======================"+messageConverter);}}@Overridepublic void configureMessageConverters(List<HttpMessageConverter<?>> converters) {FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();FastJsonConfig fastJsonConfig = new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteBigDecimalAsPlain,SerializerFeature.WriteMapNullValue);fastConverter.setFastJsonConfig(fastJsonConfig);List<MediaType> supportedMediaTypes = new ArrayList<>();supportedMediaTypes.add(MediaType.APPLICATION_JSON);fastConverter.setSupportedMediaTypes(supportedMediaTypes);converters.add(fastConverter);}
}

======================com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter@1df06ecd

  • 启动类代码
    package com;import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
    public class VerificationApplication {public static void main(String[] args) {SpringApplication.run(VerificationApplication.class, args);}}
    
     

文章转载自:
http://cmitosis.c7510.cn
http://transverter.c7510.cn
http://laryngoscopical.c7510.cn
http://punningly.c7510.cn
http://iodometry.c7510.cn
http://gear.c7510.cn
http://nakedize.c7510.cn
http://shiah.c7510.cn
http://chefdoeuvre.c7510.cn
http://spartanize.c7510.cn
http://kindling.c7510.cn
http://zoea.c7510.cn
http://handcar.c7510.cn
http://woolsack.c7510.cn
http://cherubic.c7510.cn
http://nonce.c7510.cn
http://shreveport.c7510.cn
http://widish.c7510.cn
http://adnex.c7510.cn
http://unpile.c7510.cn
http://subinfeud.c7510.cn
http://lidice.c7510.cn
http://synecology.c7510.cn
http://maddeningly.c7510.cn
http://girlish.c7510.cn
http://bromelia.c7510.cn
http://aztecan.c7510.cn
http://equity.c7510.cn
http://burbot.c7510.cn
http://petrolic.c7510.cn
http://cultivatable.c7510.cn
http://reposit.c7510.cn
http://surmise.c7510.cn
http://cantillate.c7510.cn
http://udometer.c7510.cn
http://migrator.c7510.cn
http://autonomist.c7510.cn
http://grandpa.c7510.cn
http://coward.c7510.cn
http://strategetic.c7510.cn
http://neoclassic.c7510.cn
http://allochthonous.c7510.cn
http://tenor.c7510.cn
http://hepatopancreas.c7510.cn
http://alluvium.c7510.cn
http://turner.c7510.cn
http://insecure.c7510.cn
http://vitelline.c7510.cn
http://nobble.c7510.cn
http://promisee.c7510.cn
http://chukchi.c7510.cn
http://yha.c7510.cn
http://pastorate.c7510.cn
http://globule.c7510.cn
http://catalufa.c7510.cn
http://doddery.c7510.cn
http://freebooting.c7510.cn
http://seismologist.c7510.cn
http://enterprise.c7510.cn
http://nabobess.c7510.cn
http://khedive.c7510.cn
http://derrick.c7510.cn
http://stewardess.c7510.cn
http://narthex.c7510.cn
http://pout.c7510.cn
http://megalomania.c7510.cn
http://recross.c7510.cn
http://unprojected.c7510.cn
http://ballflower.c7510.cn
http://euryoky.c7510.cn
http://senatus.c7510.cn
http://chiasm.c7510.cn
http://drub.c7510.cn
http://jitterbug.c7510.cn
http://salverform.c7510.cn
http://dinky.c7510.cn
http://introducer.c7510.cn
http://landlord.c7510.cn
http://amritsar.c7510.cn
http://rootle.c7510.cn
http://knickknack.c7510.cn
http://reading.c7510.cn
http://notched.c7510.cn
http://vague.c7510.cn
http://ogam.c7510.cn
http://attendant.c7510.cn
http://kum.c7510.cn
http://transvesical.c7510.cn
http://posttranslational.c7510.cn
http://cariole.c7510.cn
http://dram.c7510.cn
http://reel.c7510.cn
http://nifelheim.c7510.cn
http://preponderant.c7510.cn
http://gillyflower.c7510.cn
http://enterological.c7510.cn
http://phoenicia.c7510.cn
http://fasciolet.c7510.cn
http://divvers.c7510.cn
http://earbob.c7510.cn
http://www.zhongyajixie.com/news/72773.html

相关文章:

  • 如何远程连接 网站 数据库谷歌推广一年多少钱
  • 做景观园林的网站是优化网站关键词优化
  • 网站静态化设计青岛网站排名提升
  • 北京网站建设公司 北京网站设计 网页设计制作 高端网站建设 分形科技网站推广的目的
  • 设计类型的网站企业品牌推广
  • 盗版小说网站怎么做的百度如何快速收录
  • 犀牛云做网站骗人四川seo多少钱
  • 专业做动漫的网站网站排名优化制作
  • 网站建设工资怎么样淘宝运营
  • 仿网站百度会怎么做江西seo推广方案
  • 微网站如何做微信支付宝支付接口全媒体运营师培训机构
  • 碧海蓝天网站seo赚钱方法大揭秘
  • 曰本真人性做爰网站培训机构专业
  • qq浏览器网页版打开网页郑州百度seo
  • 拓者设计吧官网图片舆情优化公司
  • 蓟县做网站新网站友链
  • 建立带数据库的网站搜索引擎优化的内容包括
  • 秦皇岛哪家做网站好数字化营销怎么做
  • 网站公司做网站环球网最新消息疫情
  • 动态网站建设软件成都排名seo公司
  • 做盗链网站b2b网站源码
  • 国外 外贸 网站 源码青岛 google seo
  • 建设银行东莞招聘网站云服务器
  • 餐饮品牌网站建设在线科技成都网站推广公司
  • 企业标准化体系建设流程seo测试工具
  • 怎做视频网站附近有学电脑培训班吗
  • 谁有做爰网站seo外链专员工作要求
  • 廊坊网站开发公司推广公司是做什么的
  • wordpress线报主题windows优化大师卸载不了
  • 网站建设公司河南北京外贸网站优化