Skip to content

@Validated validation group not working on request body of List #32886

Closed as not planned
@anaconda875

Description

@anaconda875

Given:

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class VocabularyRequest {
  @Null(groups = CollectionCreation.class)
  @NotNull(groups = VocabularyCreation.class)
  private Long collectionId;

  @Valid private List<MeaningVariantRequest> meaningVariants;
}

This @Validated works:

  @PostMapping(consumes = APPLICATION_JSON_VALUE)
  @ResponseStatus(HttpStatus.CREATED)
  @Override
  public Mono<VocabularyResponse> create(
      @Validated(VocabularyCreation.class) @RequestBody VocabularyRequest request) {
    return super.create(request);
  }

But this (applied on a List) not:

  @PostMapping(value = "/bulk", consumes = APPLICATION_JSON_VALUE)
  @ResponseStatus(HttpStatus.CREATED)
  @Validated(VocabularyCreation.class)
  public Flux<VocabularyResponse> createBatch(
      @RequestBody List<@Valid VocabularyRequest> requests) {
    return service(VocabularyService.class).createBatch(requests);
  }

Change to this, still not work:

  @PostMapping(value = "/bulk", consumes = APPLICATION_JSON_VALUE)
  @ResponseStatus(HttpStatus.CREATED)
  public Flux<VocabularyResponse> createBatch(
      @Validated(VocabularyCreation.class) @RequestBody List<VocabularyRequest> requests) {
    return service(VocabularyService.class).createBatch(requests);
  }

If changing to @RequestBody List<@Validated(VocabularyCreation.class) VocabularyRequest> requests, got compile error:

'@Validated' not applicable to type use

NOTE: By "not working", I mean validation group not working. Not sure if @Valid works or not since I didnot observe it

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by another

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions