Skip to content
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

Increase reusability of Validator [SPR-15314] #19877

spring-projects-issues opened this issue Mar 5, 2017 · 0 comments

Increase reusability of Validator [SPR-15314] #19877

spring-projects-issues opened this issue Mar 5, 2017 · 0 comments
in: core type: enhancement


Copy link

@spring-projects-issues spring-projects-issues commented Mar 5, 2017

Daniel Gulyas opened SPR-15314 and commented

Quick summary


It would be really cool if the Validator implementations could be reused at the Service level hassle-free.

It would be cool because:

  • It's a common scenario that there's a second request source using the same dto (think webmvc / rest and mq), adding the second source involves extra work if it doesn't provide the binding in an other way, without using implementations of the Errors interface
  • Increases code reuse, since we use the same Validator on both Service-level and Controller-level
  • Would promote validation at the service-level a bit

Example scenario when that happens:

  1. There's a web-mvc project, controller <-dto-> service, at the controller-side the dto is validated with the Validator
  2. There's a business need to implement a secondary source of requests (let's say an mq)

Now there's a possibility to reuse the Validator created for the controller at the service level, but for me it seems to involves quite a hassle, it would be nice to make that convenient.


  • Create an interface which implements the simplified Errors interface
    • Can be instantiated with the target object only
    • Doesn't necessary have to store all the rejected properties, tracking if there was any errors might be enough
  • Create an abstract class which implements Validator
    • Boolean validate(Object target) is implemented here

The namings for me seem to be a bit weak, they could handle suggestions I'm pretty sure.

For existing Validator implementations there's only need to extend this abstract class and it'll turn into a validator which is convenient to use at the service level, please see the attached java files, this might be a bit invasive although.


This is just an idea and i'm kinda new to Spring and to Java in general so the proposal will probably include foolish design mistakes, i looked it up and so far i haven't seen anything which would make reusing of these easy, please point it out if there's already some.

If that's cool to do and there's a consensus i could make a pr for this in the coming days.

Let me know what you think!


@spring-projects-issues spring-projects-issues added type: enhancement in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.x Backlog milestone Jan 11, 2019
@jhoeller jhoeller removed this from the 5.x Backlog milestone Aug 24, 2020
@jhoeller jhoeller added this to the General Backlog milestone Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core type: enhancement
None yet

No branches or pull requests

2 participants