Skip to content

Metadata generated by the configuration properties annotation processor can miss inherited properties from nested classes #21626

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

Closed
kazuki43zoo opened this issue May 30, 2020 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@kazuki43zoo
Copy link
Contributor

kazuki43zoo commented May 30, 2020

Some properties of 3rd party provided class with inheritance relationship cannot be render to configuration metadata.

Versions

  • Spring Boot 2.3.0.RELEASE

Details

For example, following class provides from 3rd-party library:

Example 1

public class BaseConfig {
  private boolean boolValue;
  private int intValue;
  private final Nest nest = new Nest();
  // getter and setter ...
}
public class ChildConfig extends BaseConfig {
  private long longValue;
  private final NestInChild childNest = new NestInChild();
  // getter and setter ...
  public static class NestInChild {
    private boolean boolValue;
    private int intValue;
    // getter and setter ...
  }
}
  @Bean
  @ConfigurationProperties(prefix = "my.child")
  public ChildConfig childConfig() {
    return new ChildConfig();
  }

Above configuration is valid and bind to all properties but the spring-boot-configuration-processor cannot render the metadata of the BaseConfig#nest property (nested property on parent class).

Example 2

public class OverrideChildConfig extends BaseConfig {
  private long longValue;
  private final CustomNest nest = new CustomNest();
  @Override
  public CustomNest getNest() { // override getter as return the custom nested object
    return nest;
  }
  // getter and setter ...

  public static class CustomNest extends Nest { // custom class of nested class defined in parent class
    private long longValue;
    // getter and setter ...
  }
}
  @Bean
  @ConfigurationProperties(prefix = "my.override-child")
  public OverrideChildConfig overrideChildConfig() {
    return new OverrideChildConfig();
  }

Above configuration is valid and bind to all properties but the spring-boot-configuration-processor cannot render the metadata of the OverrideChildConfig#nest property.

Executable examples

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 30, 2020
@kazuki43zoo
Copy link
Contributor Author

I've published the executable example.

@philwebb
Copy link
Member

We might be able to refine PropertyDescriptor.isParentTheSame to detect these types. Processing complicated class relationships with the annotation processor is unfortunately quite difficult.

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 30, 2020
@philwebb philwebb added this to the 2.2.x milestone May 30, 2020
@kazuki43zoo
Copy link
Contributor Author

@philwebb

Thanks for your quick response !!
I found a workaround as follow:

For Example1

public class SpringBootChildConfig extends ChildConfig {
  @ConfigurationProperties("my.child.nest") // mark nested configuration property on sub class
  @Override
  public Nest getNest() {
    return super.getNest();
  }
  @ConfigurationProperties("my.child.child-nest")  // mark nested configuration property on sub class
  @Override
  public ChildNest getChildNest() {
    return super.getChildNest();
  }
}

For Example2

public class SpringBootOverrideChildConfig extends OverrideChildConfig {
  @ConfigurationProperties("my.override-child.nest")  // mark nested configuration property on sub class
  @Override
  public CustomNest getNest() { // override getter as return the custom nested object
    return super.getNest();
  }
}

@philwebb philwebb modified the milestones: 2.2.x, 2.3.x Dec 16, 2020
@wilkinsona wilkinsona modified the milestones: 2.3.x, 2.4.x Jun 10, 2021
@wilkinsona wilkinsona modified the milestones: 2.4.x, 2.5.x Nov 17, 2021
@wilkinsona wilkinsona modified the milestones: 2.5.x, 2.6.x May 19, 2022
@philwebb philwebb self-assigned this Jun 18, 2022
@philwebb philwebb changed the title Some properties on inheritance relationship class cannot be render to configuration metadata Metadata generated by the configuration properties annotation processor can miss inherited properties from nested classes Jun 21, 2022
@philwebb philwebb modified the milestones: 2.6.x, 2.6.9 Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants