|
@@ -1,6 +1,5 @@
|
|
|
package com.gxzc.zen.common.config.response
|
|
|
|
|
|
-import com.fasterxml.jackson.databind.DeserializationFeature
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper
|
|
|
import com.gxzc.zen.common.config.response.annotation.ZenResponseFilter
|
|
|
import com.gxzc.zen.common.config.response.annotation.ZenResponseFilters
|
|
@@ -25,12 +24,16 @@ import org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJack
|
|
|
@ControllerAdvice
|
|
|
class DynamicFilterResponseBodyAdvice : AbstractMappingJacksonResponseBodyAdvice() {
|
|
|
|
|
|
+// @Autowired
|
|
|
+// @Qualifier(ZenJsonConfigurer.CONVERTER_NAME)
|
|
|
+// private lateinit var converter: MappingJackson2HttpMessageConverter
|
|
|
+
|
|
|
@Autowired
|
|
|
- @Qualifier(ZenJsonConfigurer.CONVERTER_NAME)
|
|
|
- private lateinit var converter: MappingJackson2HttpMessageConverter
|
|
|
+ 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) }
|
|
|
+// converter.objectMapper = ObjectMapper().apply { configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) }
|
|
|
+ objectMapper.setMixIns(null)
|
|
|
return super.supports(returnType, converterType) &&
|
|
|
(returnType.getMethodAnnotation(ZenResponseFilter::class.java) != null
|
|
|
|| returnType.getMethodAnnotation(ZenResponseFilters::class.java) != null)
|
|
@@ -40,14 +43,14 @@ class DynamicFilterResponseBodyAdvice : AbstractMappingJacksonResponseBodyAdvice
|
|
|
val jsonSerializer = ZenJsonSerializer()
|
|
|
returnType.methodAnnotations.forEach {
|
|
|
if (it is ZenResponseFilter) {
|
|
|
- jsonSerializer.filter(it)
|
|
|
+ jsonSerializer.filter(objectMapper, it)
|
|
|
} else if (it is ZenResponseFilters) {
|
|
|
it.value.forEach {
|
|
|
- jsonSerializer.filter(it)
|
|
|
+ jsonSerializer.filter(objectMapper, it)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
bodyContainer.filters = jsonSerializer.jacksonFilter
|
|
|
- converter.objectMapper = jsonSerializer.mapper
|
|
|
+// converter.objectMapper = jsonSerializer.mapper
|
|
|
}
|
|
|
}
|