Skip to content

Description metadata not generated when using @ConfigurationProperties with Java Record #34224

Closed as not planned
@bwgjoseph

Description

@bwgjoseph

The generated spring-configuration-metadata.json does not generate description when using @ConfigurationProperties with Java Record

@ConfigurationProperties(prefix = "web.cors.record")
public record CorsRecordConfiguration(
    /**
     * allowedOrigins description (record)
     */
    List<String> allowedOrigins,
    /**
     * allowedMethods description (record)
     */
    List<String> allowedMethods) {}

Generated metadata

{
  "groups": [
    {
      "name": "web.cors.record",
      "type": "com.bwgjoseph.springbootmvnstarter.CorsRecordConfiguration",
      "sourceType": "com.bwgjoseph.springbootmvnstarter.CorsRecordConfiguration"
    }
  ],
  "properties": [
    {
      "name": "web.cors.record.allowed-methods",
      "type": "java.util.List<java.lang.String>",
      "sourceType": "com.bwgjoseph.springbootmvnstarter.CorsRecordConfiguration"
    },
    {
      "name": "web.cors.record.allowed-origins",
      "type": "java.util.List<java.lang.String>",
      "sourceType": "com.bwgjoseph.springbootmvnstarter.CorsRecordConfiguration"
    }
  ],
  "hints": []
}

When not using with Java Record, it actually works as expected

@ConfigurationProperties(prefix = "web.cors.class")
@ConstructorBinding // needed this to generate the description
public class CorsClassConfiguration {
    /**
     * allowedOrigins description (class)
     */
    private final List<String> allowedOrigins;
    /**
     * allowedMethods description (class)
     */
    private final List<String> allowedMethods;

    public CorsClassConfiguration(List<String> allowedOrigins, List<String> allowedMethods) {
        this.allowedOrigins = allowedOrigins;
        this.allowedMethods = allowedMethods;
    }
}
{
  "groups": [
    {
      "name": "web.cors.class",
      "type": "com.bwgjoseph.springbootmvnstarter.CorsClassConfiguration",
      "sourceType": "com.bwgjoseph.springbootmvnstarter.CorsClassConfiguration"
    }
  ],
  "properties": [
    {
      "name": "web.cors.class.allowed-methods",
      "type": "java.util.List<java.lang.String>",
      "description": "allowedMethods description (class)",
      "sourceType": "com.bwgjoseph.springbootmvnstarter.CorsClassConfiguration"
    },
    {
      "name": "web.cors.class.allowed-origins",
      "type": "java.util.List<java.lang.String>",
      "description": "allowedOrigins description (class)",
      "sourceType": "com.bwgjoseph.springbootmvnstarter.CorsClassConfiguration"
    }
  ],
  "hints": []
}

Adding @ConstructorBinding on Java Record does not work either


spring-boot: 2.7.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions