ソースを参照

修复ZenRequestFilters失效的问题

NorthLan 6 年 前
コミット
6ef2b8e93b

+ 8 - 9
zen-core/src/main/kotlin/com/gxzc/zen/common/config/response/DynamicFilterResponseBodyAdvice.kt

@@ -1,10 +1,8 @@
 package com.gxzc.zen.common.config.response
 
-import com.fasterxml.jackson.databind.ObjectMapper
 import com.gxzc.zen.common.config.response.annotation.ZenResponseFilter
 import com.gxzc.zen.common.config.response.annotation.ZenResponseFilters
 import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.beans.factory.annotation.Qualifier
 import org.springframework.core.MethodParameter
 import org.springframework.http.MediaType
 import org.springframework.http.converter.HttpMessageConverter
@@ -24,16 +22,17 @@ import org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJack
 @ControllerAdvice
 class DynamicFilterResponseBodyAdvice : AbstractMappingJacksonResponseBodyAdvice() {
 
-//    @Autowired
+    @Autowired
 //    @Qualifier(ZenJsonConfigurer.CONVERTER_NAME)
-//    private lateinit var converter: MappingJackson2HttpMessageConverter
+    private lateinit var converter: MappingJackson2HttpMessageConverter
 
-    @Autowired
-    private lateinit var objectMapper: ObjectMapper
+//    @Autowired
+//    private lateinit var objectMapper: ObjectMapper
 
     override fun supports(returnType: MethodParameter, converterType: Class<out HttpMessageConverter<*>>): Boolean {
 //        converter.objectMapper = ObjectMapper().apply { configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) }
-        objectMapper.setMixIns(null)
+        converter.objectMapper.setMixIns(null)
+//        objectMapper.setMixIns(null)
         return super.supports(returnType, converterType) &&
                 (returnType.getMethodAnnotation(ZenResponseFilter::class.java) != null
                         || returnType.getMethodAnnotation(ZenResponseFilters::class.java) != null)
@@ -43,10 +42,10 @@ class DynamicFilterResponseBodyAdvice : AbstractMappingJacksonResponseBodyAdvice
         val jsonSerializer = ZenJsonSerializer()
         returnType.methodAnnotations.forEach {
             if (it is ZenResponseFilter) {
-                jsonSerializer.filter(objectMapper, it)
+                jsonSerializer.filter(converter.objectMapper, it)
             } else if (it is ZenResponseFilters) {
                 it.value.forEach {
-                    jsonSerializer.filter(objectMapper, it)
+                    jsonSerializer.filter(converter.objectMapper, it)
                 }
             }
         }