If I have some objects similar to
public record OtherThing(
Integer number
) { }
public record Thing(
OtherThing otherThing
) { }
And then I have validators for these similar to
public static final Validator<OtherThing> otherThingValidator = ValidatorBuilder.<OtherThing>of()
.constraint(OtherThing::number, "number", c -> c.notNull().positive())
.build();
public static final Validator<Thing> thingValidator = ValidatorBuilder.<Thing>of()
.nest(Thing::otherThing, "", otherThingValidator)
.build();
Then if I validate an object that looks like
var myThing = new Thing(new OtherThing(-1)); // This will fail due to -1 not being positive
Then the name that ends up in the constraintviolation for this will be .number. I can see why this happens since we are doing .nest, but I was hoping that since we provide "" as the name yavi would omit appending the leading . there. The outcome that I would like to have is to just get number as the name in the constraintviolation.
Is it possible to achieve this and still be able to nest the validators like this?
(Of course, in this simple case you might ask why I dont just put the number directly on the "Thing" object, that would resolve the problem. But in "real life" the objects are larger and contain more fields and I would very much like to separate the validators like this to let me reuse them easier. :) )
If I have some objects similar to
And then I have validators for these similar to
Then if I validate an object that looks like
Then the name that ends up in the constraintviolation for this will be
.number. I can see why this happens since we are doing.nest, but I was hoping that since we provide""as the name yavi would omit appending the leading.there. The outcome that I would like to have is to just getnumberas the name in the constraintviolation.Is it possible to achieve this and still be able to nest the validators like this?
(Of course, in this simple case you might ask why I dont just put the number directly on the "Thing" object, that would resolve the problem. But in "real life" the objects are larger and contain more fields and I would very much like to separate the validators like this to let me reuse them easier. :) )