Turns out I didn't ask the correct question for the issue I had :/ So for the case people find this topic from a similar issue, the answer to my actual issue follows here.
The problem arises with a nested yaml trying to "short cut" on the model hierarchy, so given the following yaml:
foo:
bar:
baz:
bum: "hello"
I was trying to model the hierarchy as follows:
@ConfigurationProperties(prefix = "foo")
@ConstructorBinding
public record Foo(BarBaz barBaz) {}
// ---
@ConfigurationProperties(prefix = "foo.bar.baz")
@ConstructorBinding
public record BarBaz(String bum) {}
Here the problem arises that Foo
cannot do constructor binding for BarBaz
(not sure why). So there are two possible solutions that I found:
1. Do the full modelling (decided that this is what I prefer)
That is, don't try to skip the middle model for bar
.
@ConfigurationProperties(prefix = "foo")
@ConstructorBinding
public record Foo(Bar bar) {}
// ---
@ConfigurationProperties(prefix = "foo.bar")
@ConstructorBinding
public record Bar(Baz baz) {}
// ---
@ConfigurationProperties(prefix = "foo.bar.baz")
@ConstructorBinding
public record Baz(String bum) {}
2. Don't use @ConstructorBinding
when embedding more nestings
Simply skip the constructor binding in Foo
.
@ConfigurationProperties(prefix = "foo")
public record Foo(BarBaz barBaz) {}
// ---
@ConfigurationProperties(prefix = "foo.bar.baz")
@ConstructorBinding
public record BarBaz(String bum) {}
Although simpler, it's less consistent.