Will there be supported JAX-RS support groups?

From JSR-339:

For ease of implementation, JAX-RS MUST support processing groups other than Default.

This greatly limits the usefulness of validation in JAX-RS, because, for example, you usually use the same model object to create and update, but to create an identifier, objects should not be provided and an identifier should be specified for updating, which can be easily verified using validation groups. In general, all model objects that are used in more than one thread cannot be verified.

I don’t understand the argument of simplicity because Bean Validation already supports groups, so the JAX-RS implementation just needs to pass the group to the Bean a validation implementation such as the Hibernate Validator.

So, are there any plans to add validation groups to JAX-RS?

+4
source share
1 answer

Turns out it supports validation groups. From the same JSR-339:

Having @Valid will check all constraint annotations that adorn the Java bean class. This check will be performed in the default processing group if the @ConvertGroup annotation is not present .

For example, to confirm the bean account in my user groups Createor Update, rather than in a group Default:

@POST
@Consumes(MediaType.APPLICATION_JSON)
Response createAccount(@Valid @ConvertGroup(from = Default.class, to = Create.class)
    Account account)

@POST
@Consumes(MediaType.APPLICATION_JSON)
Response updateAccount(@Valid @ConvertGroup(from = Default.class, to = Update.class)
    Account account)

public class Account {

    @Null(groups = Create.class)
    @NotNull(groups = Update.class)
    private String Id;

}

public interface Create {}

public interface Update {}
+4
source

Source: https://habr.com/ru/post/1668197/


All Articles