0

I want to perform not empty validation on Controller request param but the response contains controller method name and request param name.Generally this should be avoided.

Controller class:

@PutMapping("/{id}/trains")
@ApiOperation(value = "Associate train with ticket")
public String associateTrainsToTicket(
        @RequestBody @Size(min = 1, message = "{Trains request list should not be empty.}") Set<Long> tickets,
        @Valid @PathVariable(name = "id") Long id) 
{

}

Current Response :

{
    "success": false,
    "validationError": {
        "Code": "EC_1001",
        "Messages": [
            "associateTrainsToTicket.tickets: Trains request list should not be empty."
        ]
    }
}

Required Response:

{
    "success": false,
    "validationError": {
        "Code": "EC_1001",
        "Messages": [
            "Trains request list should not be empty."
        ]
    }
}
Klaus
  • 1,641
  • 1
  • 10
  • 22
  • Answers at [this](https://stackoverflow.com/questions/56467824/how-to-get-query-parameter-name-from-constraintviolationexception) question has some pointers to the solution. – Smile May 14 '20 at 07:46
  • @Smile here the validation is working fine but the controller method and request body field name are attaching as key in the response message.I do not wan't to have that – Ritesh Tiwari May 14 '20 at 12:06
  • Answer mentioned in the above comment also provides solution for exactly same problem – Smile May 14 '20 at 12:10

0 Answers0