Skip to content

Validation of @ConfigurationProperties does not happen for nested properties #3510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dsyer opened this issue Jul 15, 2015 · 4 comments
Closed

Comments

@dsyer
Copy link
Member

dsyer commented Jul 15, 2015

E.g. this works:

@ConfigurationProperties("config")
class Props {

    @NotEmpty
    private String value = "";

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

}

this doesn't

@ConfigurationProperties("config")
class Config {
    @NotNull
    // this works
    private Props props = new Props();

    public Props getProps() {
        return props;
    }

    public void setProps(Props props) {
        this.props = props;
    }

    @Validated // shouldn't be necessary, just tried it in case
    public static class Props {

        @NotEmpty
        private String value = "";

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

    }
}
@dsyer dsyer added type: bug A general bug question and removed type: bug A general bug labels Jul 15, 2015
@dsyer
Copy link
Member Author

dsyer commented Jul 15, 2015

This works:

@ConfigurationProperties("config")
class Config {
    @NotNull
    @Valid
    private Props props = new Props();

    public Props getProps() {
        return props;
    }

    public void setProps(Props props) {
        this.props = props;
    }

    public static class Props {

        @NotEmpty
        // doesn't work here
        private String value = "";

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

    }
}

@dsyer dsyer closed this as completed Jul 15, 2015
snicoll added a commit that referenced this issue Jul 23, 2015
* pr/3566:
  Polish
  Document validation of nested components
@taotao365s
Copy link

@dsyer

why use it here? but others all wrong.

public static class Props

@philwebb
Copy link
Member

philwebb commented Jul 5, 2017

@shipengyan I'm not sure I understand the question, but here's not the best place to ask it. We like to keep the issue tracker purely for bugs and enhancements. The issue has also been closed for 2 years.

If have a general question you should ask on http://stackoverflow.com, or you can join us on http://gitter.im.

@kcotzen
Copy link

kcotzen commented Sep 9, 2019

This comment is for people who still face this issue:

For me, the salvation was this:
@ConfigurationProperties("config")
@validated <---------THIS
class Config {

It wasn't necessary the static class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants