The content of the article is as the title.
In the correlation check using ʻAssertTrue, when I tried to perform validation such as" Error 1 if
false, Error 2 if
null` ", the method was not called at the time of validation.
@AssertTrue(message = "Hogehoge")
@NotNull(message = "Fuga Fuga")
private Boolean isValid() {
/*Correlation check*/
}
From the official document, it is as follows.
To put it plainly, java.lang.Boolean
is an object, so giving method names starting with ʻis ~` is a convention violation.
It's a matter of course when you think about it, but it's complicated, so please forgive me ...
What is a getter? The JavaBeans specification specifies that a getter is a method whose
- name starts with get and has a return type but no parameter
- name starts with is, has no parameter and is returning boolean
Exhibitor: Bean Validation specification
You can have it called by changing the method name.
However, in this case, I don't think it is necessary to specify Boolean
.
There is also the issue of gettingters and names for fields.
@AssertTrue(message = "Hogehoge")
@NotNull(message = "Fuga Fuga")
private Boolean getValid() {
/*Correlation check*/
}
I couldn't find any other solution.
I thought I could run multiple correlation checks on the same field without annotating it, but it didn't work. It's quite painful to try to balance value acquisition and validation, so it's wise to separate the validation object and the value acquisition object, especially when things get complicated.
Recommended Posts