Do u have any ideas how to validate one object in this case?
I have class A which is built of two another classes B and C:
public class A{
private B b;
private C c;
}
In that case I would like to validate all fields from object B, which looks like this:
public class B{
private String name;
private Long number;
}
This kind of object A is being passed into my Controller as request object, so that I'd like to validate it before it's sent.
The point is that I'd like to validate name and number objects when they are both passed but if any of them is null then I'd just like to validate the one which is not null.
Do you guys have any ideas how to do that? I made @Valid on A object as well as on B field but it shows no ConstraintValidatonException.
Problem solved - Validation doesn't work on Restcontroller method but after passing it on Service, everthing works well. I'm going to investigate it in a free time.