ConstructorBinding in version 3.0.0-M4 will not allow ElementType.TYPE, it's caused an issue when using kotlin data class

Screen Shot 2022-08-22 at 15 38 23

Current

@Target(ElementType.CONSTRUCTOR)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ConstructorBinding {

}

Expected

@Target({ElementType.TYPE, ElementType.CONSTRUCTOR})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ConstructorBinding {
}

Comment From: philwebb

@MadeInChina @ConstructorBinding is designed to be used only on a constructor, if there's a single constructor it shouldn't be necessary. Can you provide more details about what you're trying to do and why you want to add the annotation to the type?

Comment From: hanrw

@MadeInChina @ConstructorBinding is designed to be used only on a constructor, if there's a single constructor it shouldn't be necessary. Can you provide more details about what you're trying to do and why you want to add the annotation to the type? It's will raise a problem if upgrade from 2.x version. for 2.x version ConstructorBinding support ElementType.TYPE. which means that we can add @ConstructorBinding to a data class and the recommended way to manage application properties with Kotlin can be found here spring-boot-kotlin

@ConstructorBinding in order to be able to use read-only properties.

@ConstructorBinding
@ConfigurationProperties("blog")
data class BlogProperties(var title: String, val banner: Banner) {
  data class Banner(val title: String? = null, val content: String)
}

kotlinlang - getters-and-setters The full syntax of a read-only property declaration differs from a mutable one in two ways: it starts with val instead of var and does not allow a setter

Comment From: wilkinsona

I can't see a need for @ConstructorBinding in your example. Both BlogProperties and Banner have only a single constructor so we can automatically identify the constructor to use. If you declare your data class with a secondary constructor, you can use @ConstructorBinding to identify the constructor that should be used with the help of the constructor keyword:

@ConfigurationProperties("blog")
data class BlogProperties @ConstructorBinding constructor(val title: String, val banner: Banner) {
  constructor(banner: Banner) : this("Default title", banner)
  data class Banner(val title: String? = null, val content: String)
}

Here, the constructor that takes a String and a Banner will be used for configuration property binding.

Given the above, I'm going to close this issue. If there's a situation where binding to a data class still does not work, please provide a complete yet minimal sample that reproduces the problem. We can then re-open this issue and take another look.