0

I started to use validation framework @Valid to validate json request with jax-rs

Is it possible to validate a field against another field?

So this is how I wanna construct the request body:

@JsonProperty
private Integer peopleCount

@JsonProperty
@Min(value = 0)
@Max( value = peopleCount)
private Integer personId;

So when I pass

{
     "peopleCount":2,
     "personId": 4
}

it should throw an error

but @Max( value = peopleCount) does not work since it requires a constant value

please note that I'm trying to validate against the json request itself and not the values saved in DB

Thanks in advance

Mahyar
  • 1,011
  • 2
  • 17
  • 37

1 Answers1

2

You can use custom constraint like class level constraint for cross field validation.

Alex
  • 11,451
  • 6
  • 37
  • 52