use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter in project JBM by numen06.
the class RestTemplateFactory method initMessageConverters.
public static void initMessageConverters(RestTemplate restTemplate) {
restTemplate.getMessageConverters().removeIf(new Predicate<HttpMessageConverter<?>>() {
@Override
public boolean test(HttpMessageConverter<?> t) {
if (t instanceof StringHttpMessageConverter)
return true;
if (t instanceof FormHttpMessageConverter) {
return true;
}
return false;
}
});
restTemplate.getMessageConverters().add(1, new StringHttpMessageConverter(Charset.defaultCharset()));
restTemplate.getMessageConverters().add(fileFormHttpMessageConverter);
restTemplate.getMessageConverters().add(fastJsonHttpMessageConverter);
}
use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter in project jeeagile by jeeagile.
the class AgileWebAutoConfigure method fastJsonHttpMessageConverter.
@Bean
@ConditionalOnMissingBean
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.DisableCircularReferenceDetect);
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON);
fastConverter.setSupportedMediaTypes(fastMediaTypes);
fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
fastConverter.setFastJsonConfig(fastJsonConfig);
return fastConverter;
}
use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter in project ebase-boot by ebase-projects.
the class CustomWebMvcConfig method fastJsonHttpMessageConverter.
/**
* fastjson的配置
* https://www.jianshu.com/p/02e8db6b6b23
*/
// @Bean
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteEnumUsingToString, SerializerFeature.WriteNullStringAsEmpty);
fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
fastJsonConfig.setCharset(Charset.forName("utf-8"));
// 解决Long转json精度丢失的问题
SerializeConfig serializeConfig = SerializeConfig.globalInstance;
serializeConfig.put(BigInteger.class, com.alibaba.fastjson.serializer.ToStringSerializer.instance);
serializeConfig.put(Long.class, com.alibaba.fastjson.serializer.ToStringSerializer.instance);
serializeConfig.put(Long.TYPE, com.alibaba.fastjson.serializer.ToStringSerializer.instance);
// 驼峰转下划线
// https://github.com/alibaba/fastjson/wiki/PropertyNamingStrategy_cn
// serializeConfig.setPropertyNamingStrategy(com.alibaba.fastjson.PropertyNamingStrategy.SnakeCase);
fastJsonConfig.setSerializeConfig(serializeConfig);
converter.setFastJsonConfig(fastJsonConfig);
return converter;
}
use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter in project springboot-manager by aitangbao.
the class WebMvcConfigurer method fastJsonHttpMessageConverter.
@Bean
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
FastJsonConfig config = new FastJsonConfig();
// Long类型转String类型
SerializeConfig serializeConfig = SerializeConfig.globalInstance;
// ToStringSerializer 是这个包 com.alibaba.fastjson.serializer.ToStringSerializer
serializeConfig.put(BigInteger.class, ToStringSerializer.instance);
serializeConfig.put(Long.class, ToStringSerializer.instance);
serializeConfig.put(Long.TYPE, ToStringSerializer.instance);
config.setSerializeConfig(serializeConfig);
config.setSerializerFeatures(// 保留map空的字段
SerializerFeature.WriteMapNullValue, // 将String类型的null转成""
SerializerFeature.WriteNullStringAsEmpty, // 将Number类型的null转成0
SerializerFeature.WriteNullNumberAsZero, // 将List类型的null转成[]
SerializerFeature.WriteNullListAsEmpty, // 将Boolean类型的null转成false
SerializerFeature.WriteNullBooleanAsFalse, // 日期格式转换
SerializerFeature.WriteDateUseDateFormat, // 避免循环引用
SerializerFeature.DisableCircularReferenceDetect);
config.setSerializeFilters(valueFilter);
converter.setFastJsonConfig(config);
converter.setDefaultCharset(StandardCharsets.UTF_8);
// 解决中文乱码问题,相当于在Controller上的@RequestMapping中加了个属性produces = "application/json"
List<MediaType> mediaTypeList = new ArrayList<>();
mediaTypeList.add(MediaType.APPLICATION_JSON);
converter.setSupportedMediaTypes(mediaTypeList);
return converter;
}
use of com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter in project spring_boot by hryou0922.
the class MybatisSpringBoot method fastJsonHttpMessageConverters.
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
// 格式化时间
SerializeConfig mapping = new SerializeConfig();
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
// fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastJsonConfig.setSerializeConfig(mapping);
fastConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter<?> converter = fastConverter;
return new HttpMessageConverters(converter);
}
Aggregations