1.序列化到前臺時時間變成時間戳纤垂,沒有時間格式揩慕,SpringBoot自帶的配置時間序列化格式因為已經(jīng)被替換了實現(xiàn)類所以不在生效奏候,需要使用fastJson的時間設(shè)置方式@JSONField(format ="yyyy-MM-dd HH:mm:ss")在實體類上加上次注解即可劲件。
2.在序列話到前臺時候fastjson遍歷集合會存在對象被返回的情況揉燃,以及所有請求被攔截扫尺,但是處理不是很理想的情況,貼出配置供參考
FastJsonHttpMessageConverterCustomextends 當(dāng)作一個Bean注冊
public class FastJsonHttpMessageConverterCustomextends FastJsonHttpMessageConverter {
private static SetsupportedMediaTypes;
? ? public FastJsonHttpMessageConverterCustom() {
supportedMediaTypes =new HashSet<>();
? ? ? ? supportedMediaTypes.add(MediaType.APPLICATION_JSON);
? ? ? ? supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
? ? }
@Override
? ? public boolean canRead(Type type, Class contextClass, MediaType mediaType) {
return this.supports(contextClass) &&supportedMediaTypes.contains(mediaType);
? ? }
@Override
? ? public boolean canWrite(Type type, Class clazz, MediaType mediaType) {
return super.supports(clazz) &&supportedMediaTypes.contains(mediaType);
? ? }
@Override
? ? protected void writeInternal(Object object, HttpOutputMessage outputMessage)throws IOException, HttpMessageNotWritableException {
OutputStream out = outputMessage.getBody();
? ? ? ? String text = JSON.toJSONString(object, SerializerFeature.DisableCircularReferenceDetect);
? ? ? ? byte[] bytes = text.getBytes("utf-8");
? ? ? ? out.write(bytes);
? ? }
}