Browse Source

fix 序列化

master
niohe·erbao 1 year ago
parent
commit
f659419a25
2 changed files with 8 additions and 8 deletions
  1. +5
    -5
      pmapi/src/main/java/com/ningdatech/pmapi/common/config/ConfigurerAdapter.java
  2. +3
    -3
      pmapi/src/main/java/com/ningdatech/pmapi/common/handler/GlobalResponseHandler.java

+ 5
- 5
pmapi/src/main/java/com/ningdatech/pmapi/common/config/ConfigurerAdapter.java View File

@@ -28,15 +28,15 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
// 使用 fastjson 序列化,会导致 @JsonIgnore 失效,可以使用 @JSONField(serialize = false) 替换
// FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
List<MediaType> supportMediaTypeList = new ArrayList<>();
supportMediaTypeList.add(MediaType.APPLICATION_JSON);
FastJsonConfig config = new FastJsonConfig();
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);
// converter.setFastJsonConfig(config);
// converter.setSupportedMediaTypes(supportMediaTypeList);
// converter.setDefaultCharset(StandardCharsets.UTF_8);
// converters.add(converter);
converter.setFastJsonConfig(config);
converter.setSupportedMediaTypes(supportMediaTypeList);
converter.setDefaultCharset(StandardCharsets.UTF_8);
converters.add(converter);
}
}

+ 3
- 3
pmapi/src/main/java/com/ningdatech/pmapi/common/handler/GlobalResponseHandler.java View File

@@ -44,9 +44,9 @@ public class GlobalResponseHandler implements ResponseBodyAdvice<Object> {
// ConverterType是StringHttpMessageConverter这个类型转换,
// 由于将结果封装成了自定义的ApiResponse类型,所以有ApiResponse转换成String报错
// 所以需要对String类型的返回值单独进行处理
if (o instanceof String) {
return JSONUtil.toJsonStr(apiResponse);
}
// if (o instanceof String) {
// return JSONUtil.toJsonStr(apiResponse);
// }
return ApiResponse.ofSuccess(o);
// return o;
}


Loading…
Cancel
Save