I am trying to validate a class, the validations I have to perform must be in this order: first the validation of the class itself, then the validation of nested objects and finally the custom validation. To try to order the validation I am using the @groupsequence annotation like so:
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@GroupSequence({FirstClass.class, ValidSecond.class, ValidCustom.class})
@ValidCustom(groups = ValidCustom.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public record FirstClass(
@NotEmpty(message = " mustn't be empty")
String a,
@DecimalMin("0.999")
@DecimalMax("99999999999999999.999")
Double e,
@NotNull(groups = ValidSecond.class)
PowerN n,
MaxF maxF) {
}
I created the interface:
public interface ValidSecond { }
and the custom ValidCustom.
Separately the validations work but I need to run the validation first on the father class and nested object and only for the last custom one. For how done above this does not happen and the custom is called before ValidSecond