Similar to https://github.com/spring-projects/spring-boot/issues/27141 but with one major difference - it doesn't seem to work for nested classes.

So this works:

@Validated
@ConfigurationProperties("fooBar")
record FooBarProperties(@NotNull Foo foo,
                        Optional<Bar> bar) {

    @ConstructorBinding
    FooBarProperties(Foo foo, Bar bar) {
        this(foo, Optional.ofNullable(bar));
    }

    record Bar(String value) {
    }
}

but this doesn't work:

@Validated
@ConfigurationProperties("fooBar")
record FooBarProperties(@NotNull Foo foo,
                        Optional<Bar> bar) {

    @ConstructorBinding
    FooBarProperties(Foo foo, Bar bar) {
        this(foo, Optional.ofNullable(bar));
    }

    record Bar(Optional<String> value) {
        @ConstructorBinding
        FooBarProperties(String value) {
            this(Optional.ofNullable(value)));
        }

    }
}

In second example value doesn't get wrapped into Optional but is instead null.

Comment From: wilkinsona

Thanks for the report. Unfortunately, the code as currently shared doesn't compile. Can you please provide a complete and minimal example, including the configuration properties that you're binding.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.