Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow NestedConfigurationProperty on getters #38844

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ protected boolean isNested(MetadataGenerationEnvironment environment) {
if (environment.getConfigurationPropertiesAnnotation(getGetter()) != null) {
return false;
}
if (environment.getNestedConfigurationPropertyAnnotation(getField()) != null) {
if (environment.getNestedConfigurationPropertyAnnotation(getField()) != null
|| environment.getNestedConfigurationPropertyAnnotation(getGetter()) != null) {
return true;
}
if (isCyclePresent(typeElement, getOwnerElement())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.springframework.boot.configurationsample.specific.BoxingPojo;
import org.springframework.boot.configurationsample.specific.BuilderPojo;
import org.springframework.boot.configurationsample.specific.DeprecatedLessPreciseTypePojo;
import org.springframework.boot.configurationsample.specific.DeprecatedSimplePojo;
import org.springframework.boot.configurationsample.specific.DeprecatedUnrelatedMethodPojo;
import org.springframework.boot.configurationsample.specific.DoubleRegistrationProperties;
import org.springframework.boot.configurationsample.specific.EmptyDefaultValueProperties;
Expand Down Expand Up @@ -333,6 +334,9 @@ void innerClassProperties() {
assertThat(metadata).has(Metadata.withProperty("config.third.value"));
assertThat(metadata).has(Metadata.withProperty("config.fourth"));
assertThat(metadata).isNotEqualTo(Metadata.withGroup("config.fourth"));
assertThat(metadata)
.has(Metadata.withGroup("config.fifth").ofType(DeprecatedSimplePojo.class).fromSource(InnerClassProperties.class));
assertThat(metadata).has(Metadata.withProperty("config.fifth.value").withDeprecation());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author Phillip Webb
* @since 1.2.0
*/
@Target(ElementType.FIELD)
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface NestedConfigurationProperty {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.configurationsample.specific;

/**
* POJO for use with samples needing a deprecated value.
*
* @author Jared Bates
*/
public class DeprecatedSimplePojo {

private int value;

@Deprecated
public int getValue() {
return this.value;
}

public void setValue(int value) {
this.value = value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class InnerClassProperties {

private Fourth fourth;

private final DeprecatedSimplePojo fifth = new DeprecatedSimplePojo();

public Foo getFirst() {
return this.first;
}
Expand All @@ -60,6 +62,11 @@ public void setFourth(Fourth fourth) {
this.fourth = fourth;
}

@NestedConfigurationProperty
public DeprecatedSimplePojo getFifth() {
return this.fifth;
}

public static class Foo {

private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author Phillip Webb
* @since 1.2.0
*/
@Target(ElementType.FIELD)
@Target({ ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nested
Expand Down