When springboot adds support for fastjson, it returns not json but string. How to solve it?

@Bean
    public HttpMessageConverters fastJsonHttpMessageConverters() {
        //1convert
        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
        //2fastjsonjson;
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
        //:
        List<MediaType> fastMedisTypes = new ArrayList<>();
        fastMedisTypes.add(MediaType.APPLICATION_JSON_UTF8);
        fastConverter.setSupportedMediaTypes(fastMedisTypes);
        //3convert
        fastConverter.setFastJsonConfig(fastJsonConfig);
        HttpMessageConverter<?> converter = fastConverter;
        return new HttpMessageConverters(converter);
    }

clipboard.png


Json and String can you see with the naked eye?
maybe the IDE or console automatically displays the JSON object amicably


controller is annotated with @ RestController or @ ResponseBody. The returned object is a string returned by json and put it into the json formatter to verify


.

doesn't spring boot have a MappingJackson2JsonView view, which can be used to return json

you can refer to the code example: https://gitee.com/skyarthur19.


change it to this way, it will be easy to use

FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(){
        @Override
        protected boolean supports(Class<?> clazz) {
            return clazz != String.class && super.supports(clazz);
        }
    };

Brother, I have the same problem. Have you solved it?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c1ddd3-320ec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c1ddd3-320ec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?