|
|
@ -17,7 +17,6 @@
|
|
|
|
package org.springframework.boot.test.autoconfigure.properties;
|
|
|
|
package org.springframework.boot.test.autoconfigure.properties;
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.annotation.Annotation;
|
|
|
|
import java.lang.annotation.Annotation;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
@ -110,33 +109,32 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
|
|
|
|
PropertyMapping typeMapping, Map<String, Object> properties) {
|
|
|
|
PropertyMapping typeMapping, Map<String, Object> properties) {
|
|
|
|
PropertyMapping attributeMapping = AnnotationUtils.getAnnotation(attribute,
|
|
|
|
PropertyMapping attributeMapping = AnnotationUtils.getAnnotation(attribute,
|
|
|
|
PropertyMapping.class);
|
|
|
|
PropertyMapping.class);
|
|
|
|
if (isMapped(typeMapping, attributeMapping)) {
|
|
|
|
SkipPropertyMapping skip = getMappingType(typeMapping, attributeMapping);
|
|
|
|
String name = getName(typeMapping, attributeMapping, attribute);
|
|
|
|
if (skip == SkipPropertyMapping.YES) {
|
|
|
|
ReflectionUtils.makeAccessible(attribute);
|
|
|
|
return;
|
|
|
|
Object value = ReflectionUtils.invokeMethod(attribute, annotation);
|
|
|
|
}
|
|
|
|
if (isValueMapped(value)) {
|
|
|
|
String name = getName(typeMapping, attributeMapping, attribute);
|
|
|
|
putProperties(name, value, properties);
|
|
|
|
ReflectionUtils.makeAccessible(attribute);
|
|
|
|
|
|
|
|
Object value = ReflectionUtils.invokeMethod(attribute, annotation);
|
|
|
|
|
|
|
|
if (skip == SkipPropertyMapping.ON_DEFAULT_VALUE) {
|
|
|
|
|
|
|
|
Object defaultValue = AnnotationUtils.getDefaultValue(annotation,
|
|
|
|
|
|
|
|
attribute.getName());
|
|
|
|
|
|
|
|
if (ObjectUtils.nullSafeEquals(value, defaultValue)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
putProperties(name, value, properties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isMapped(PropertyMapping typeMapping,
|
|
|
|
private SkipPropertyMapping getMappingType(PropertyMapping typeMapping,
|
|
|
|
PropertyMapping attributeMapping) {
|
|
|
|
PropertyMapping attributeMapping) {
|
|
|
|
if (attributeMapping != null) {
|
|
|
|
if (attributeMapping != null) {
|
|
|
|
return attributeMapping.map();
|
|
|
|
return attributeMapping.skip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (typeMapping != null && typeMapping.map());
|
|
|
|
if (typeMapping != null) {
|
|
|
|
}
|
|
|
|
return typeMapping.skip();
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isValueMapped(Object value) {
|
|
|
|
|
|
|
|
if (value != null && value instanceof Enum) {
|
|
|
|
|
|
|
|
Field field = ReflectionUtils.findField(value.getClass(),
|
|
|
|
|
|
|
|
((Enum<?>) value).name());
|
|
|
|
|
|
|
|
if (AnnotatedElementUtils.isAnnotated(field, UnmappedPropertyValue.class)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return SkipPropertyMapping.YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getName(PropertyMapping typeMapping, PropertyMapping attributeMapping,
|
|
|
|
private String getName(PropertyMapping typeMapping, PropertyMapping attributeMapping,
|
|
|
|