Skip to content

The getter and setter that's used during configuration property binding varies when a getter or setter has been overridden to use a subclass of the property's type #28917

@telxs

Description

@telxs

Version: Spring Boot 2.5.7

Add BeanProperty from sub class first ,then ignore exist BeanProperty in super class (only use single parameter in BiConsumer),and finally bind to the properties of the super class, resulting in the loss of the subclass property extension.

private void addProperties(Class<?> type) {
	while (type != null && !Object.class.equals(type)) {
		Method[] declaredMethods = getSorted(type, Class::getDeclaredMethods, Method::getName);
		Field[] declaredFields = getSorted(type, Class::getDeclaredFields, Field::getName);
		addProperties(declaredMethods, declaredFields);
		type = type.getSuperclass();
	}
}

private void addMethodIfPossible(Method method, String prefix, int parameterCount,
		BiConsumer<BeanProperty, Method> consumer) {
	if (method != null && method.getParameterCount() == parameterCount && method.getName().startsWith(prefix)
			&& method.getName().length() > prefix.length()) {
		String propertyName = Introspector.decapitalize(method.getName().substring(prefix.length()));
		consumer.accept(this.properties.computeIfAbsent(propertyName, this::getBeanProperty), method);
	}
}

void addSetter(Method setter) {
	if (this.setter == null || isBetterSetter(setter)) {
		this.setter = setter;
	}
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions