Skip to content

@Validated support on Iterables (and implementors) [SPR-13428] #18007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Sep 4, 2015 · 3 comments
Closed
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 4, 2015

Frédéric Camblor opened SPR-13428 and commented

Putting a @Validated annotation on @RequestBody of an Iterable (or any implementation such as List) doesn't trigger any bean validation process

To reproduce, take the following controller declaration :

@Controller
public class HelloWorldController {

    public static class Hello {
        @NotNull
        private String who;
        
        public String getWho() { return who; }
        public void setWho(String who) { this.who = who; }
    }

    // If I send JSON : {}
    // => Validation error about "who" field being mandatory (it's ok)
    @RequestMapping(value="/testWithPOJO", method=RequestMethod.POST)
    public @ResponseBody List<Hello> testPost5(@RequestBody @Validated Hello hello) {
        return Arrays.asList(hello);
    }

    // If I send JSON : [ {} ]
    // => No Validation error, bean validation is not triggered on instances, this looks weird
    @RequestMapping(value="/testWithArray", method=RequestMethod.PUT)
    public @ResponseBody List<Hello> testPost1(@RequestBody @Validated List<Hello> hellos) {
        return hellos;
    }

    @ExceptionHandler(MethodArgumentNotValidException.class)
    @ResponseStatus(value = HttpStatus.PRECONDITION_FAILED)
    public @ResponseBody List<ObjectError> handleValidationFailure(MethodArgumentNotValidException exception) {
        return exception.getBindingResult().getAllErrors();
    }
}

WDYT ?


Affects: 3.2 GA, 4.0 GA, 4.1 GA

Issue Links:

2 votes, 3 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Sep 4, 2015

Frédéric Camblor commented

Seems like duplicate of #16917 (I cannot change issue status it seems)

@spring-projects-issues
Copy link
Collaborator Author

mathsworld2001 commented

I recently came across this very same issue. Some at stackoverflow claims that this should already work as expected. I still cannot make this work. Can anyone confirm the current status of this ticket?

@rstoyanchev
Copy link
Contributor

Duplicate of #16917.

@rstoyanchev rstoyanchev added the status: duplicate A duplicate of another issue label Jan 29, 2019
@rstoyanchev rstoyanchev removed this from the 5.x Backlog milestone Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants