question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat(): validation involving multiple fields

See original GitHub issue

Hi,

I really like the approach YAVI take to simplify the bean validation, but I would like to know how (and if it is possible simply) we can do a “two field validation”

For example:

data class Foo(val min: Int, val max: Int) // very simple model, can happen on more than two fields with more than one type

I would like to be valid only if min is smaller than max. I don’t find anything about it in the current API which is very annoying for me because a huge part of my business domain has this kind of (form) validation on our class.

I find a solution by transforming the value to Map then doing the validation on each value… but it’s not very efficient (putting into a map and then extracting it)

Thanks for your help

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
davinkevincommented, Nov 28, 2018

I don’t know if it’s simply possible, but I propose something like this (the name of the method can be changed, I don’t have enough imagination 😊)

var validator = Validator.builder(Foo::class.java)
        .constraintGlobal({ foo: Foo -> foo.max > foo.min }, "max", ViolationMessage.of("max.range", "'max' must be greater than 'min'")) })
        .build()

I don’t know if all the parameters are required here (especially the max), but if not, we can remove it.

0reactions
makingcommented, Nov 29, 2018

will be released in 0.20.0 I really appreciate your feedback

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - How can I validate two or more fields in combination?
I now have a situation where the combination of two fields has to be validated: public class MyModel { public Integer getValue1() {...
Read more >
How to handle validations involving several fields?
It's often enough to validate each field in isolation: * email should contain a @; * password should be more than four characters....
Read more >
feat: add option to define class level custom decorators #182
I created a decorator already, but it's bound to the field and not the class, so I lack access to multiple fields. ......
Read more >
Cross field validation in Spring and JEE - | Dev in Web
Learn how to validate related parameters of request together in Spring or JEE application. See a class level cross field validator in ...
Read more >
User Input Validation in Razor Pages
Input Validation is the process whereby you ensure that values provided by the user of your Razor Pages web site are of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found