From ConfigurationProperties javadoc:

Binding is either performed by calling setters on the annotated class or, if
@ConstructorBinding is in use, by binding to the constructor
parameters.

Since records can't and shouldn't have setters, could Spring Boot apply @ConstructorBinding behavior by default for @ConfigurationProperties annotated records?

Comment From: wilkinsona

That sounds like a good idea to me, thanks for the suggestion. We should be able to tell if a class is a record without using Java 16 API (Class#isRecord) by checking to see if its superclass is java.lang.Record.

Comment From: wilkinsona

The implementation for this is pretty straightforward, but testing it as part of our Java 8-based build is not. Flagging for team meeting so that we can discuss what to do.

Comment From: philwebb

The only solution I can think of is to have a test that runs only in our Java 16 build. The problem is creating that record class. I guess we could include a binary class file or possibly use cglib to generate the bytecode. Even without a test, the code is so minimal that I'd be tempted to merge it.

Comment From: wilkinsona

Thanks, Phil. I'm not sure it's possible with cglib but it is with ByteBuddy. I now have a test that fails without my changes and passes with them in place.

Comment From: snicoll

@wilkinsona looking at the commit, it doesn't look like the annotation processor has been updated to apply this mode with a record so I suspect this won't generate the proper metadata or have I missed something?

Comment From: wilkinsona

Nope, I just forgot about it.