Here is my java code
class AbstractO{
public interface Save{}; // for groups
public interface Update{}; // for groups
}
class A extends AbstractO{
public Integer id;
@NotNull(groups={A.Save.class})
@Valid
public B b;
}
class B extends AbstractO{
@NotNull(groups={B.Update.class})
public Integer id;
@NotNull(groups={A.Save.class})
public Integer prop
}
// controller method
@ResponseBody
public ResponseEntity<A> save(@RequestBody @Validated(value = { A.Save.class }) A ,
BindingResult bindingResult) {
// code goes here...
}
Issue
At time of saving A I want to have validation. Validation group is set as A.Save
in controller method so B b
in class A
is is getting validated as notnull.
However I want to have validation of prop
of class B
while saving A
, So I have added @Valid
on B b
and mentioned group A.Save
on prop so that validate that only when A is getting saved.
My problem is even id
of B has on B.Update
as group, it still validates in controller (with group A.Save
). May be issue is the @Valid
annotation but without that annotation it does not validates nested things.