0

Currently, I am validating my request using javax validation.

Set<ConstraintViolation<Request>> constraintViolations = validator
            .validate(Request); 

So from constraint violations I want two things,

  1. constraint violation.getPropertyPath() which will return which fields is violating
  2. I want the invalid value that I was passing in the request for the fields from the constraintViolations variable

So how we can get the invalid value?

For 2. I tried using constraintViolation.getInvalidValue() this but it is giving like com.practice.domain.PaymentInstrumentRequest@258d8cb5

I want specific value that I have passed in that field.

Hulk
  • 6,399
  • 1
  • 30
  • 52
  • Related: https://stackoverflow.com/questions/36555057/get-field-name-when-javax-validation-constraintviolationexception-is-thrown – Hulk Feb 10 '21 at 13:20
  • Thanks Hulk, I refer that but currently when I am doing constraintViolation.getInvalidValue() , it is returning whole request data that I am passing. I only want that field value. – Farahnaaz Pathan Feb 10 '21 at 13:33
  • Sorry, can't tell more than that - have never used this myself. Perhaps it would help to show an example for a constraint and input violating it, and a sample output for what exactly you want to find out about the violation. – Hulk Feb 10 '21 at 14:06

0 Answers0