com.alibaba.fastjson.support.config.FastJsonConfig Java Examples
The following examples show how to use
com.alibaba.fastjson.support.config.FastJsonConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebAppConfigurer.java From spring-cloud-learning with MIT License | 6 votes |
@Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { super.configureMessageConverters(converters); FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); // PrettyFormat:结果是否格式化,默认为false // WriteMapNullValue:是否输出值为null的字段,默认为false // DisableCircularReferenceDetect:消除对同一对象循环引用的问题,默认为false fastJsonConfig.setSerializerFeatures( SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect ); fastConverter.setFastJsonConfig(fastJsonConfig); converters.add(fastConverter); }
Example #2
Source File: FastjsonConfiguration.java From seed with Apache License 2.0 | 6 votes |
@Bean public HttpMessageConverters fastjsonConverter(){ List<SerializerFeature> serializerFeatureList = new ArrayList<>(); serializerFeatureList.add(SerializerFeature.PrettyFormat); serializerFeatureList.add(SerializerFeature.QuoteFieldNames); serializerFeatureList.add(SerializerFeature.WriteMapNullValue); serializerFeatureList.add(SerializerFeature.WriteNullListAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullNumberAsZero); serializerFeatureList.add(SerializerFeature.WriteNullStringAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullBooleanAsFalse); serializerFeatureList.add(SerializerFeature.WriteDateUseDateFormat); SerializerFeature[] serializerFeatures = new SerializerFeature[serializerFeatureList.size()]; serializerFeatureList.toArray(serializerFeatures); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setCharset(StandardCharsets.UTF_8); fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); fastJsonConfig.setSerializerFeatures(serializerFeatures); FastJsonHttpMessageConverter fastjson = new FastJsonHttpMessageConverter(); fastjson.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastjson); }
Example #3
Source File: CustomMVCConfiguration.java From spring-boot-starter-netty with GNU General Public License v3.0 | 6 votes |
@Bean FastJsonHttpMessageConverter getFastJsonConv() { FastJsonHttpMessageConverter conv = new FastJsonHttpMessageConverter(); FastJsonConfig oFastJsonConfig = new FastJsonConfig(); oFastJsonConfig.setSerializerFeatures( SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat ); conv.setFastJsonConfig(oFastJsonConfig); List<MediaType> types = new ArrayList<>(); types.add(MediaType.APPLICATION_JSON_UTF8); types.add(MediaType.APPLICATION_JSON); conv.setSupportedMediaTypes(types); return conv; }
Example #4
Source File: WebMvcConfigurer.java From mysiteforme with Apache License 2.0 | 6 votes |
/** * fastjson序列化 * * */ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { super.configureMessageConverters(converters); List<MediaType> supportedMediaTypes = new ArrayList<>(); supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); fastJsonHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); // 自定义时间格式 fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteNullNumberAsZero,SerializerFeature.WriteNullBooleanAsFalse,SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullStringAsEmpty,SerializerFeature.WriteNullListAsEmpty,SerializerFeature.WriteDateUseDateFormat, SerializerFeature.BrowserCompatible,SerializerFeature.WriteNonStringKeyAsString); converters.add(fastJsonHttpMessageConverter); converters.add(responseBodyConverter()); }
Example #5
Source File: WebMvcConfig.java From SpringBoot-Base-System with GNU Lesser General Public License v3.0 | 6 votes |
/** * fastJson相关设置 * * @time 2018年4月10日 下午4:57:40. * * @version V1.0 * @return FastJsonConfig */ private FastJsonConfig getFastJsonConfig() { FastJsonConfig fastJsonConfig = new FastJsonConfig(); List<SerializerFeature> serializerFeatureList = new ArrayList<SerializerFeature>(); serializerFeatureList.add(SerializerFeature.PrettyFormat); serializerFeatureList.add(SerializerFeature.WriteMapNullValue); serializerFeatureList.add(SerializerFeature.WriteNullStringAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullListAsEmpty); serializerFeatureList.add(SerializerFeature.DisableCircularReferenceDetect); SerializerFeature[] serializerFeatures = serializerFeatureList .toArray(new SerializerFeature[serializerFeatureList.size()]); fastJsonConfig.setSerializerFeatures(serializerFeatures); return fastJsonConfig; }
Example #6
Source File: FastjsonConfiguration.java From seed with Apache License 2.0 | 6 votes |
@Bean public HttpMessageConverters fastjsonConverter(){ List<SerializerFeature> serializerFeatureList = new ArrayList<>(); serializerFeatureList.add(SerializerFeature.PrettyFormat); serializerFeatureList.add(SerializerFeature.QuoteFieldNames); serializerFeatureList.add(SerializerFeature.WriteMapNullValue); serializerFeatureList.add(SerializerFeature.WriteNullListAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullNumberAsZero); serializerFeatureList.add(SerializerFeature.WriteNullStringAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullBooleanAsFalse); serializerFeatureList.add(SerializerFeature.WriteDateUseDateFormat); SerializerFeature[] serializerFeatures = new SerializerFeature[serializerFeatureList.size()]; serializerFeatureList.toArray(serializerFeatures); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setCharset(StandardCharsets.UTF_8); fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); fastJsonConfig.setSerializerFeatures(serializerFeatures); FastJsonHttpMessageConverter fastjson = new FastJsonHttpMessageConverter(); fastjson.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastjson); }
Example #7
Source File: FastjsonConfiguration.java From seed with Apache License 2.0 | 6 votes |
@Bean public HttpMessageConverters fastjsonConverter(){ List<SerializerFeature> serializerFeatureList = new ArrayList<>(); serializerFeatureList.add(SerializerFeature.PrettyFormat); serializerFeatureList.add(SerializerFeature.QuoteFieldNames); serializerFeatureList.add(SerializerFeature.WriteMapNullValue); serializerFeatureList.add(SerializerFeature.WriteNullListAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullNumberAsZero); serializerFeatureList.add(SerializerFeature.WriteNullStringAsEmpty); serializerFeatureList.add(SerializerFeature.WriteNullBooleanAsFalse); serializerFeatureList.add(SerializerFeature.WriteDateUseDateFormat); SerializerFeature[] serializerFeatures = new SerializerFeature[serializerFeatureList.size()]; serializerFeatureList.toArray(serializerFeatures); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setCharset(StandardCharsets.UTF_8); fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); fastJsonConfig.setSerializerFeatures(serializerFeatures); FastJsonHttpMessageConverter fastjson = new FastJsonHttpMessageConverter(); fastjson.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastjson); }
Example #8
Source File: HttpBasicAuthConfig.java From xmfcn-spring-cloud with Apache License 2.0 | 6 votes |
/** * 替换springMVC JSON格式化工具为FastJSON,同时支持输出value=null的字段 * * @return http message converters */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters(){ //1.需要定义一个convert转换消息的对象; FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); //2:添加fastJson的配置信息; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue); fastJsonConfig.setSerializeFilters(); //3处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); //4.在convert中添加配置信息. fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters((HttpMessageConverter<?>) fastJsonHttpMessageConverter); }
Example #9
Source File: BeanConfig.java From xmfcn-spring-cloud with Apache License 2.0 | 6 votes |
/** * 替换springMVC JSON格式化工具为FastJSON,同时支持输出value=null的字段 * * @return http message converters */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { //1.需要定义一个convert转换消息的对象; FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); //2:添加fastJson的配置信息; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue); fastJsonConfig.setSerializeFilters(); //3处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); //4.在convert中添加配置信息. fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastJsonHttpMessageConverter); }
Example #10
Source File: BeanConfig.java From xmfcn-spring-cloud with Apache License 2.0 | 6 votes |
/** * 替换springMVC JSON格式化工具为FastJSON,同时支持输出value=null的字段 * * @return http message converters */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { //1.需要定义一个convert转换消息的对象; FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); //2:添加fastJson的配置信息; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue); fastJsonConfig.setSerializeFilters(); //3处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); //4.在convert中添加配置信息. fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(fastJsonHttpMessageConverter); }
Example #11
Source File: WebConfigurer.java From mySpringBoot with Apache License 2.0 | 6 votes |
/** * 修改自定义消息转换器 * * @param converters */ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { FastJsonHttpMessageConverter4 converter = new FastJsonHttpMessageConverter4(); converter.setSupportedMediaTypes(getSupportedMediaTypes()); FastJsonConfig config = new FastJsonConfig(); config.setSerializerFeatures( // String null -> "" SerializerFeature.WriteNullStringAsEmpty, // Number null -> 0 SerializerFeature.WriteNullNumberAsZero, //禁止循环引用 SerializerFeature.DisableCircularReferenceDetect ); converter.setFastJsonConfig(config); converter.setDefaultCharset(Charset.forName("UTF-8")); converters.add(converter); }
Example #12
Source File: FastJsonProvider.java From uavstack with Apache License 2.0 | 6 votes |
/** * Method that JAX-RS container calls to deserialize given value. */ public Object readFrom(Class<Object> type, // Type genericType, // Annotation[] annotations, // MediaType mediaType, // MultivaluedMap<String, String> httpHeaders, // InputStream entityStream) throws IOException, WebApplicationException { try { FastJsonConfig fastJsonConfig = locateConfigProvider(type, mediaType); return JSON.parseObject(entityStream, fastJsonConfig.getCharset(), genericType, fastJsonConfig.getFeatures()); } catch (JSONException ex) { throw new WebApplicationException("JSON parse error: " + ex.getMessage(), ex); } }
Example #13
Source File: DefaultWebMvcConfigurerAdapter.java From dk-foundation with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { FastJsonHttpMessageConverter fastConvert = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai"); JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; fastJsonConfig.setSerializerFeatures(SerializerFeature.BrowserCompatible, SerializerFeature.BrowserSecure, SerializerFeature.PrettyFormat, SerializerFeature.WriteDateUseDateFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect); /** * 解决Long转json精度丢失的问题 */ SerializeConfig serializeConfig = SerializeConfig.globalInstance; serializeConfig.put(BigInteger.class, ToStringSerializer.instance); serializeConfig.put(Long.class, ToStringSerializer.instance); serializeConfig.put(Long.TYPE, ToStringSerializer.instance); fastJsonConfig.setSerializeConfig(serializeConfig); fastConvert.setFastJsonConfig(fastJsonConfig); converters.add(fastConvert); }
Example #14
Source File: WebMvcConfig.java From littleca with Apache License 2.0 | 6 votes |
@Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { //1.需要定义一个convert转换消息的对象; FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); //2.添加fastJson的配置信息,比如:是否要格式化返回的json数据; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //3处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON); fastJsonConfig.setCharset(Charset.forName("UTF-8")); //4.在convert中添加配置信息. fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); //5.将convert添加到converters当中. converters.add(1,fastJsonHttpMessageConverter); }
Example #15
Source File: WebMvcConfig.java From littleca with Apache License 2.0 | 6 votes |
@Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { //1.需要定义一个convert转换消息的对象; FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); //2.添加fastJson的配置信息,比如:是否要格式化返回的json数据; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //3处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON); fastJsonConfig.setCharset(Charset.forName("UTF-8")); //4.在convert中添加配置信息. fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); //5.将convert添加到converters当中. converters.add(1, fastJsonHttpMessageConverter); }
Example #16
Source File: FastjsonConfig.java From spring-boot-demo-all with Apache License 2.0 | 6 votes |
@Bean public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() { FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures( SerializerFeature.PrettyFormat, SerializerFeature.WriteClassName, SerializerFeature.WriteMapNullValue ); List<MediaType> fastMediaTypes = new ArrayList<MediaType>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); ValueFilter valueFilter = new ValueFilter() { public Object process(Object o, String s, Object o1) { if (null == o1) { o1 = ""; } return o1; } }; fastJsonConfig.setSerializeFilters(valueFilter); converter.setSupportedMediaTypes(fastMediaTypes); converter.setFastJsonConfig(fastJsonConfig); return converter; }
Example #17
Source File: WebMvcConfig.java From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
/** * 自定义消息转换器:使用 Fastjson 替换 Spring Boot 默认使用的 Jackson * * @param converters 消息转换器 */ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { // 清除默认 Json 转换器 converters.removeIf(converter -> converter instanceof MappingJackson2HttpMessageConverter); // 配置 FastJson FastJsonConfig config = new FastJsonConfig(); config.setSerializerFeatures(SerializerFeature.QuoteFieldNames, SerializerFeature.WriteEnumUsingToString, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); // 添加 FastJsonHttpMessageConverter FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); fastJsonHttpMessageConverter.setFastJsonConfig(config); List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes); converters.add(fastJsonHttpMessageConverter); // 添加 StringHttpMessageConverter,解决中文乱码问题 StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8); converters.add(stringHttpMessageConverter); }
Example #18
Source File: FastJsonAutoConfiguration.java From utils with Apache License 2.0 | 6 votes |
@Bean @ConditionalOnMissingBean(com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.class) public HttpMessageConverters customConverters(FastJsonHttpMessageConverter converter) { Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); if (null == converter) { Class<?> converterClass = properties.getConverter(); converter = (FastJsonHttpMessageConverter) BeanUtils.instantiate(converterClass); } FastJsonConfig config = new FastJsonConfig(); List<SerializerFeature> features = properties.getFeatures(); if (!CollectionUtils.isBlank(features)) { SerializerFeature[] featureArray = new SerializerFeature[features.size()]; config.setSerializerFeatures(features.toArray(featureArray)); } converter.setFastJsonConfig(config); messageConverters.add(converter); return new HttpMessageConverters(true, messageConverters); }
Example #19
Source File: WebConfig.java From spring-boot-cookbook with Apache License 2.0 | 6 votes |
@Bean public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() { FastJsonHttpMessageConverter httpMessageConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.QuoteFieldNames, SerializerFeature.WriteEnumUsingToString, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); fastJsonConfig.setSerializeFilters(new ValueFilter() { @Override public Object process(Object o, String s, Object source) { if (source == null) { return ""; } if (source instanceof Date) { return ((Date) source).getTime(); } return source; } }); httpMessageConverter.setFastJsonConfig(fastJsonConfig); return httpMessageConverter; }
Example #20
Source File: WebMvcConfig.java From yue-library with Apache License 2.0 | 6 votes |
/** * <p>使用FastJson优先于默认的Jackson做json解析 * <p>https://github.com/alibaba/fastjson/wiki/%E5%9C%A8-Spring-%E4%B8%AD%E9%9B%86%E6%88%90-Fastjson */ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { // 1. 确认是否启用FastJsonHttpMessageConverter if (!webProperties.isEnabledFastJsonHttpMessageConverter()) { return; } // 2. 配置FastJsonHttpMessageConverter FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); FastJsonConfig config = new FastJsonConfig(); config.setDateFormat(JSON.DEFFAULT_DATE_FORMAT); config.setSerializerFeatures( SerializerFeature.PrettyFormat, SerializerFeature.BrowserCompatible, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullBooleanAsFalse, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullStringAsEmpty ); converter.setFastJsonConfig(config); converters.add(0, converter); log.info("【初始化配置-FastJsonHttpMessageConverter】默认配置为false,当前环境为true:使用FastJson优先于默认的Jackson做json解析 ... 已初始化完毕。"); }
Example #21
Source File: WebMvcConfig.java From spring-boot-cookbook with Apache License 2.0 | 6 votes |
@Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { FastJsonHttpMessageConverter httpMessageConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.QuoteFieldNames, SerializerFeature.WriteEnumUsingToString, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); fastJsonConfig.setSerializeFilters(new ValueFilter() { @Override public Object process(Object o, String s, Object source) { if (source == null) { return ""; } if (source instanceof Date) { return ((Date) source).getTime(); } return source; } }); httpMessageConverter.setFastJsonConfig(fastJsonConfig); converters.add(httpMessageConverter); }
Example #22
Source File: RedisConfig.java From sophia_scaffolding with Apache License 2.0 | 6 votes |
/** * 使用@Bean注入fastJsonHttpMessageConvert,fastJson序列化 */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters(){ // 1、需要先定义一个 convert 转换消息的对象; FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); //2、添加fastJson 的配置信息,比如:是否要格式化返回的json数据; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //2-1 处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastConverter.setSupportedMediaTypes(fastMediaTypes); //3、在convert中添加配置信息. fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }
Example #23
Source File: RedisConfig.java From sophia_scaffolding with Apache License 2.0 | 6 votes |
/** * 使用@Bean注入fastJsonHttpMessageConvert,fastJson序列化 */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters(){ // 1、需要先定义一个 convert 转换消息的对象; FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); //2、添加fastJson 的配置信息,比如:是否要格式化返回的json数据; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //2-1 处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastConverter.setSupportedMediaTypes(fastMediaTypes); //3、在convert中添加配置信息. fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }
Example #24
Source File: RedisConfig.java From sophia_scaffolding with Apache License 2.0 | 6 votes |
/** * 使用@Bean注入fastJsonHttpMessageConvert,fastJson序列化 */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters(){ // 1、需要先定义一个 convert 转换消息的对象; FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); //2、添加fastJson 的配置信息,比如:是否要格式化返回的json数据; FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //2-1 处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastConverter.setSupportedMediaTypes(fastMediaTypes); //3、在convert中添加配置信息. fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }
Example #25
Source File: FastJsonConfiguration.java From momo-cloud-permission with Apache License 2.0 | 6 votes |
@Bean public HttpMessageConverters fastJsonConfigure(){ FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //日期格式化 fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); //修改配置返回内容的过滤 fastJsonConfig.setSerializerFeatures( SerializerFeature. WriteMapNullValue,//是否输出值为null的字段,默认为false SerializerFeature.WriteDateUseDateFormat,//格式化标签 SerializerFeature.WriteNullListAsEmpty , //List字段如果为null,输出为[],而非null SerializerFeature.DisableCircularReferenceDetect,//消除对同一对象循环引用的问题,默认为false(如果不配置有可能会进入死循环) SerializerFeature.WriteMapNullValue,//是否输出值为null的字段,默认为false。 SerializerFeature.WriteNullStringAsEmpty,//字符类型字段如果为null,输出为"",而非null SerializerFeature.WriteNullBooleanAsFalse//Boolean字段如果为null,输出为false,而非null ); converter.setFastJsonConfig(fastJsonConfig); //处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); converter.setSupportedMediaTypes(fastMediaTypes); converter.setFastJsonConfig(fastJsonConfig); //将fastjson添加到视图消息转换器列表内 return new HttpMessageConverters(converter); }
Example #26
Source File: FastJsonConfiguration.java From momo-cloud-permission with Apache License 2.0 | 6 votes |
@Bean public HttpMessageConverters fastJsonConfigure(){ FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); //日期格式化 fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); //修改配置返回内容的过滤 fastJsonConfig.setSerializerFeatures( // SerializerFeature. WriteMapNullValue,//是否输出值为null的字段,默认为false SerializerFeature.WriteDateUseDateFormat//格式化标签 // SerializerFeature.WriteNullListAsEmpty ,//List字段如果为null,输出为[],而非null // SerializerFeature.DisableCircularReferenceDetect,//消除对同一对象循环引用的问题,默认为false(如果不配置有可能会进入死循环) // SerializerFeature.WriteMapNullValue,//是否输出值为null的字段,默认为false。 // SerializerFeature.WriteNullStringAsEmpty//字符类型字段如果为null,输出为"",而非null // SerializerFeature.WriteNullBooleanAsFalse//Boolean字段如果为null,输出为false,而非null ); converter.setFastJsonConfig(fastJsonConfig); //处理中文乱码问题 List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); converter.setSupportedMediaTypes(fastMediaTypes); converter.setFastJsonConfig(fastJsonConfig); //将fastjson添加到视图消息转换器列表内 return new HttpMessageConverters(converter); }
Example #27
Source File: Application.java From AthenaServing with Apache License 2.0 | 5 votes |
/** * fastjson 转换器 * * @param converters */ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { super.configureMessageConverters(converters); FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue); List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastConverter.setSupportedMediaTypes(fastMediaTypes); fastConverter.setFastJsonConfig(fastJsonConfig); converters.add(fastConverter); }
Example #28
Source File: Application.java From bookmark with MIT License | 5 votes |
@Bean public HttpMessageConverters fastJsonHttpMessageConverters() { // 1.定义一个converters转换消息的对象 FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); // 2.添加fastjson的配置信息,比如: 是否需要格式化返回的json数据 FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect); // 3.在converter中添加配置信息 fastConverter.setFastJsonConfig(fastJsonConfig); // 5.返回HttpMessageConverters对象 return new HttpMessageConverters(fastConverter); }
Example #29
Source File: MessageConfig.java From framework with Apache License 2.0 | 5 votes |
/** * * Description: <br> * * @author 王伟<br> * @taskId <br> * @return <br> */ @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { // 1、需要先定义一个 convert 转换消息对象; FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setFeatures(Feature.AllowISO8601DateFormat); fastConverter.setFastJsonConfig(fastJsonConfig); return new HttpMessageConverters(new StringHttpMessageConverter(), fastConverter); }
Example #30
Source File: WebConfig.java From sanshanblog with Apache License 2.0 | 5 votes |
@Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); FastJsonConfig config = new FastJsonConfig(); config.setDateFormat("yyyy-MM-dd HH:mm:ss"); fastJsonHttpMessageConverter.setFastJsonConfig(config); converters.add(fastJsonHttpMessageConverter); converters.add(resourceHttpMessageConverter); super.configureMessageConverters(converters); }