0
構成するので、私は、これは動作しません グループにBean検証アノテーションを追加できますか?
このような@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
@Retention(RUNTIME)
@Documented
@Repeatable(NotNullOnCreate.List.class)
@ReportAsSingleViolation
@Constraint(validatedBy = {})
@NotNull(groups = Create.class)
@interface NotNullOnCreate {
String message() default "{javax.validation.constraints.NotNull.message}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
@Retention(RUNTIME)
@Documented
@interface List {
NotNullOnCreate[] value();
}
}
NotNullOnCreate
を作成し、私は唯一のCreate
グループで働くことNotNull
チェックを構築したいので、私はこの
@Data
public static class TestDto {
@NotNullOnCreate
// @NotNull(groups = Create.class) // instead of this
private String id;
}
のように書くことができます制約の注釈(ConstraintDescriptorImpl#createComposingConstraintDescriptor参照)グループは、注釈のグループをホストするように設定されます(「デフォルト」)。
私もこの試みたClass<?>[] groups() default {Create.class};
、これは許可されていません、デフォルトグループは空でなければなりません。
どうすればこの問題を解決できますか?私はどこにでもグループを書いてはいけません。
EDIT
- 明示的なグループ
- とHV-1355制約の注釈を作成します。これは現時点では不可能である実行可能なデモプロジェクトhv-annotation-with-group
ありがとう、私はHV-1355を作成しました – wener