Tlaloc-ES
Tlaloc-ES

Reputation: 5282

How can validate an array of a class with its validations?

Hi I have the next code:

public class PkData{
    @NotNull
    Private String stringA;
    ...
}

public class A{
    private PkData pkData = new PkData();

    @NotNull
    private Integer sequenceNumberA;

    @NotNull
    Private String stringA;

    @NotNull
    Private String stringB;
...
}

public class B{
    @NotNull
    private A a;
...
}

When call Set<ConstraintViolation<User>> violations = validator.validate(B);

The validator only return B errors, and not sub clases errors like A.stringA as not null.

How can do get these validations.

And if B be a B[] how can do it?

Any idea? thanks

Upvotes: 1

Views: 61

Answers (2)

Andy Sug
Andy Sug

Reputation: 244

You need to put @Validannotation on private A a; in class B

Upvotes: 1

Bijay Yadav
Bijay Yadav

Reputation: 958

You can create validate methods in each Class A and class PkData which will check the value of each private fields present in them and validate those values.

Upvotes: 1

Related Questions