修改fastjson2序列化时将byte[]序列化为Base64字符串,反之在反序列化时将Base64字符串反序列化为byte[]

This commit is contained in:
joylink_zhangsai 2023-06-29 16:11:15 +08:00
parent c046a52214
commit 37445a2723

View File

@ -3,6 +3,7 @@ package club.joylink.xiannccda.configuration;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.JSONWriter.Feature;
import com.alibaba.fastjson2.reader.ObjectReader;
import com.alibaba.fastjson2.support.spring6.http.converter.FastJsonHttpMessageConverter;
import com.alibaba.fastjson2.writer.ObjectWriter;
@ -22,6 +23,8 @@ public class JsonConfig implements ApplicationRunner {
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
converter.getFastJsonConfig().setWriterFeatures(Feature.WriteByteArrayAsBase64);
converter.getFastJsonConfig().setReaderFeatures(JSONReader.Feature.Base64StringAsByteArray);
return new HttpMessageConverters(converter);
}