netceteragroup / valdr-bean-validation

Java Bean Validation plugin
MIT License
35 stars 21 forks source link

Support JSR 303 validation groups #31

Open hagis opened 8 years ago

hagis commented 8 years ago

We need to validate an object of class A differently in different situations, and we use validation groups for that in the backend.

Now we would like to use valdr in the frontend, but there is no support for validation groups.

We are planning to implement support for validation groups in our own copy of valdr-bean-validation, but would ultimately like to see that feature pulled into valdr-bean-validation.

Our rough plan is as follows:

  1. Add a new config parameter "includeValidationGroups" default false.
  2. When that is enabled, add any groups defined in the bean constraint annotations into the generated JSON:
"Plan": {
  "name": {
    "size": {
      "min": 2,
      "message": "{javax.validation.constraints.Size.message}",
      "max": 255,
      "groups": [
        "ValidationGroup.Active.class"
      ]
    }
  }
}

My question is: would you consider a PR on this feature? If so, is the above approach ok?

marcelstoer commented 8 years ago

Sure, sounds reasonable.

The validation group name is just a string but I wouldn't include the .class suffix anyway. For the valdr JSON groups must be an optional attribute as I'm not sure how the .Net backend could support that.

hagis commented 8 years ago

Great! Will have a go at this. It might take several weeks calendar time depending on our backlog prioritization.

hagis commented 7 years ago

In our project we are currently using versions of valdr-bean-validation and valdr frontend containing this modification.

I would appreciate if you took the time to look into merging these PRs, as we would like to get back to using the off the shelf valdr.

marcelstoer commented 7 years ago

Your bump was due, Tero, I agree. Last night I made a mental note to talk to the valdr maintainers to analyze your PR. Once that one is approved I'll merge the Java support as well.