1.序列化到前台时时间变成时间戳,没有时间格式,SpringBoot自带的配置时间序列化格式因为已经被替换了实现类所以不在生效,需要使用fastJson的时间设置方式@JSONField(format ="yyyy-MM-dd HH:mm:ss")在实体类上加上次注解即可。
2.在序列话到前台时候fastjson遍历集合会存在对象被返回的情况,以及所有请求被拦截,但是处理不是很理想的情况,贴出配置供参考
FastJsonHttpMessageConverterCustomextends 当作一个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);
}
}
网友评论