From 6659309ea516ee925a72fb1a467f15a75b6d4be8 Mon Sep 17 00:00:00 2001 From: shiyiyue1102 Date: Wed, 20 Nov 2024 10:03:21 +0800 Subject: [PATCH] nacos config serialization ignore null field. --- .../nacos/annotation/NacosAnnotationProcessor.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/annotation/NacosAnnotationProcessor.java b/spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/annotation/NacosAnnotationProcessor.java index e46144da9..577837369 100644 --- a/spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/annotation/NacosAnnotationProcessor.java +++ b/spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/annotation/NacosAnnotationProcessor.java @@ -42,6 +42,7 @@ import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.BeansException; +import org.springframework.beans.NotReadablePropertyException; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -748,10 +749,17 @@ private static String[] getNullPropertyNames(Object source) { Set nullPropertyNames = new HashSet<>(); for (PropertyDescriptor pd : pds) { String propertyName = pd.getName(); - Object propertyValue = src.getPropertyValue(propertyName); - if (propertyValue == null) { + try { + Object propertyValue = src.getPropertyValue(propertyName); + if (propertyValue == null) { + nullPropertyNames.add(propertyName); + } + } + catch (NotReadablePropertyException e) { + //ignore nullPropertyNames.add(propertyName); } + } return nullPropertyNames.toArray(new String[0]); }