ConstraintValidatorContext removes iterable nesting, bug?
by John Hendrikx
Hi list,
I'm currently trying to use JSR-303 validation inside a project with a
complicated hierarchical structure that needs validation. What I find
is that even in custom validators, the ConstraintValidatorContext is
limiting me in what paths I can construct to indicate the proper error
location.
For example, when my custom rule is called as part of an iteration, and
I want to add another level of iteration in the path like so:
.addPropertyNode("y").inIterable().atKey("z")
...it will overwrite the current iterable part of the path (allowing me
to modify the "parent" context it looks like). So instead of getting:
root["x"]["z"].y
It removes the ["x"] and results in: root["z"].y which is clearly wrong.
If I add a dummy property node first, I can atleast see the root iterable:
.addPropertyNode("$DUMMY$")
.addPropertyNode("y").inIterable().atKey("z")
Results in: root["x"].$DUMMY$["z"].y
I also think it is a shame that nested Iterables are not supported.
Hierarchical structures can have constructs like Map<String, List<X>>
and currently annotating X has no effect at all.
--John
8 years, 6 months