SpELAssert not working on fields
Closed this issue · 2 comments
e-g-hategan commented
Using SpELAsssert 1.1.0 and Spring Boot 1.3.6.
SpELAsserts work fine at type level but the equivalent ones don't work at all at field level.
WORKS
@SpELAssert("value != null") class TypeAssertedRequest { public String value; }
DOESN'T WORK
class FieldAssertedRequest { @SpELAssert("#this != null") public String value; }
I've also put together a small maven project to reproduce it.
aristotll commented
It seems that all null values are considered valid.
See
e-g-hategan commented
Thanks for looking into this @aristotll
I guess that's fair, many implementations of constraint validators do the same.
The workaround is to have an additional @NotNull
validator like below:
class FieldAssertedRequest { @NotNull @SpELAssert("#this != null") public String value; }