Home Ask Login Register

Developers Planet

Your answer is one click away!

ankit February 2016

Rest service post bean validation

I am stuck with a problem of post body attributes validation. I need to throw an exception or show an error, when an invalid attribute is passed down to JSON request body. I have no idea how to do that? Please help.

FYI : I am using Jersey API.


Sheetal Mohan Sharma February 2016

Why cant you use Jersey's bean validation support examples and docs- here?

Bean Validation support in Jersey is provided as an extension module and needs to be mentioned explicitly in your pom.xml file (in case of using Maven): <dependency> <groupId>org.glassfish.jersey.ext</groupId> <artifactId>jersey-bean-validation</artifactId> <version>2.22.1</version> </dependency>

you can define your custom validations and ValidationError messages.

In JSP add validation-errors tags and you are done.

<div class="validation-errors">
    <div class="validation-error">

Or even you can sent json format error response.

[ {
   "message" : "xxxxxx.",
   "messageTemplate" : "{xxx.does.not.exist}",
   "path" : "abc.xyz.<return value>"
} ]

Post Status

Asked in February 2016
Viewed 1,445 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life