Skip to content

feat: support JSR-303 validation groups in BeanValidationBinder - #25187

Open
totally-not-ai[bot] wants to merge 2 commits into
mainfrom
feat/7032-bean-validation-groups
Open

feat: support JSR-303 validation groups in BeanValidationBinder#25187
totally-not-ai[bot] wants to merge 2 commits into
mainfrom
feat/7032-bean-validation-groups

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

What

BeanValidationBinder previously validated only the constraints of the default validation group, with no way to opt in to constraints that declare a group (#7032). This adds first-class validation group support:

BeanValidationBinder

  • New constructor BeanValidationBinder(Class<BEAN>, Class<?>...) and setValidationGroups(Class<?>...) configure the groups used for all validation triggered by the binder, including single-field validation on value change. Groups replace the default group, so Default.class must be listed explicitly to also validate ungrouped constraints. Passing no groups restores the previous behavior.
  • validate(Class<?>...) runs a one-shot validation against the given groups without changing the configured ones — useful for constraints that only matter on save and shouldn't fire on every keystroke.
  • getValidationGroups() exposes the groups in effect (returning the one-shot groups while such a validation is running), so bean-level validators added with withValidator can validate against the same groups as the field-level validation.
  • The required indicator now takes the configured groups into account, so a constraint that is never validated no longer marks a field as required.

BeanValidator

  • New constructors accepting the validation groups either as a Class<?>... array or as a SerializableSupplier<Class<?>[]>, the latter allowing the groups to change after the validator is created (this is how the binder feeds its current groups in).
  • getValidationGroups() accessor; validateValue is now called with the resolved groups.

Tests

BeanValidationGroupsTest covers the new semantics: group-scoped constraints being validated only when their group is configured, the default group replacement rule, the required indicator honoring groups, and one-shot validate(Class<?>...) leaving the configured groups untouched.

Fixes #7032

Pins down the current behaviour of BeanValidationBinder with respect to
JSR-303 validation groups (group scoped constraints are never validated,
the required indicator ignores groups) and specifies the semantics the
group support asked for in #7032 should have: a group configured on the
binder that is used for all validation, and a one-shot validation
against an explicit group that does not change the configured groups.

The target semantics are exercised through a test local binder that
plugs a group aware validator in via configureBinding, which is the
workaround needed until the API exists.

Part of #7032
BeanValidationBinder validated only the constraints of the default
validation group, and there was no way to opt in to constraints that
declare a group.

The validation groups to validate against can now be configured with
setValidationGroups, or given to the constructor, in which case they are
used for all validation triggered by the binder, including the validation
of a single field when its value changes. As the groups replace the
default group, Default.class has to be listed explicitly to validate the
constraints without a group as well.

In addition, validate(Class<?>...) runs a single validation against the
given groups without changing the configured ones, which makes it
possible to only check constraints that are relevant when the data is
saved, without validating them on every value change.

The groups in effect are also available to bean level validators through
getValidationGroups, which return the groups of an ongoing one-shot
validation while it is running.

BeanValidator accepts the validation groups either as an array or as a
supplier, the latter allowing the groups to be changed after the
validator has been created.

The required indicator now takes the configured validation groups into
account as well, so that a constraint that is not validated no longer
marks a field as required.

Fixes #7032
@totally-not-ai totally-not-ai Bot changed the title feat/7032 bean validation groups feat: support JSR-303 validation groups in BeanValidationBinder Aug 12, 2026
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Test Results

 1 451 files  + 1   1 452 suites  +1   1h 27m 11s ⏱️ + 1m 23s
10 410 tests +16  10 343 ✅ +16  67 💤 ±0  0 ❌ ±0 
10 846 runs  +16  10 778 ✅ +16  68 💤 ±0  0 ❌ ±0 

Results for commit 23d92ba. ± Comparison against base commit a1e3b17.

♻️ This comment has been updated with latest results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: 🔎Iteration reviews

Development

Successfully merging this pull request may close these issues.

Feature Request: Allow configuration of Validation Groups

1 participant