Skip to content

Add support for javax.validation.constraints.NotBlank #1753

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
fdutton opened this issue Jan 17, 2022 · 4 comments
Closed

Add support for javax.validation.constraints.NotBlank #1753

fdutton opened this issue Jan 17, 2022 · 4 comments
Assignees
Labels
Milestone

Comments

@fdutton
Copy link

fdutton commented Jan 17, 2022

Currently, Jsr303AwarePropertyMetadata indicates that a property is required if the property is annotated with javax.validation.constraints.NotNull but it does not give the same consideration to properties annotated with javax.validation.constraints.NotBlank.

The presence of the @NotBlank annotation should be considered equivalent to the property being annotated with @NotNull @Pattern(regex = "^\\s*(\\S+\\s*)+$").

Ideally, Jsr303AwarePropertyMetadata would support this annotation by updating its isRequired and getPattern methods. However, Jsr303AwarePropertyMetadata currently assumes that a property has zero-or-one @Pattern annotations, which is not valid. A property may have zero-or-more patterns.

In the case where a property is annotated with both @NotBlank and @Pattern, it may be acceptable to ignore the pattern implied by the @NotBlank annotation. Otherwise, it may be necessary to introduce a getPatterns method and deprecate getPattern.

@odrotbohm
Copy link
Member

Sounds reasonable. Care to draft a PR to discuss?

@fdutton
Copy link
Author

fdutton commented Jan 17, 2022

It would be my pleasure.

What is the process? Should I create a fork and submit the pull-request from there?

@odrotbohm
Copy link
Member

Sounds good to me. Don't get overenthusiastic with formalities, I'll take care of those. The change plus a test case is just fine.

@odrotbohm odrotbohm self-assigned this Jan 18, 2022
@odrotbohm odrotbohm changed the title Add support for javax.validation.constraints.NotBlank Add support for javax.validation.constraints.NotBlank Jan 18, 2022
@fdutton
Copy link
Author

fdutton commented Jan 18, 2022

I cloned the main branch and did a build without making any changes and this unit-test fails. It appears to be a race condition because it does not fail with stepping through the code with a debugger.

[INFO] Running org.springframework.hateoas.config.EnableHypermediaSupportIntegrationTest
[ERROR] Tests run: 21, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.699 s <<< FAILURE! - in org.springframework.hateoas.config.EnableHypermediaSupportIntegrationTest
[ERROR] registersNoOpMessageResolverIfMessagesBundleMissing  Time elapsed: 0.018 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: 

expected: INSTANCE
 but was: org.springframework.hateoas.mediatype.MessageSourceResolver@e998bad
	at org.springframework.hateoas.config.EnableHypermediaSupportIntegrationTest.lambda$registersNoOpMessageResolverIfMessagesBundleMissing$11(EnableHypermediaSupportIntegrationTest.java:308)
	at org.springframework.hateoas.config.EnableHypermediaSupportIntegrationTest.registersNoOpMessageResolverIfMessagesBundleMissing(EnableHypermediaSupportIntegrationTest.java:306)

@odrotbohm odrotbohm added this to the 1.5 M2 milestone Jan 28, 2022
odrotbohm added a commit that referenced this issue Jan 28, 2022
Slightly more compact default regex pattern. Untangle defaulting condition in PropertyMetdata.getPattern(). Extract test cases into dedicated methods. Couple of Javadoc fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants