【JSON】解决FastJson中“$ref 循环引用”的问题

2017-11-03  本文已影响0人  KingdomCoder

fastjson在循环引用时对象转化成json会发生$ref:


$ref

禁用FastJson的“循环引用检测”特性。


禁用FastJson的“循环引用检测”特性
@Configuration
public class HttpConvertConfiguration {
    
     @Bean
        public HttpMessageConverters fastJsonHttpMessageConverters() {
           FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
           FastJsonConfig fastJsonConfig = new FastJsonConfig();
           fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect);
           fastConverter.setFastJsonConfig(fastJsonConfig);
           HttpMessageConverter<?> converter = fastConverter;
           return new HttpMessageConverters(converter);
        }

}
上一篇 下一篇

猜你喜欢

热点阅读