Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation for generated JAXB Classes (JSR 303 / Spring)

I Generated domain objects from schema (request & response) using JAXB (maven-jaxb2-plugin)
I would like add validations (notnull /empty) for couple of attributes. I would like to have custom Bean Validation, the application is a REST service, i'm using Spring 3 and JSR 303 but i dont think i can use JSR 303 to validate the object as it is generated from the schema.

can someone give me a nudge in the right direction on how to get this done.

like image 622
sundark Avatar asked Apr 29 '11 22:04

sundark


2 Answers

We've been using the Krasa JAXB plugin to generate JSR 303-annotated model beans from XSD files, and then telling Spring to automatically validate the input beans. This results in very nice, very terse, very DRY code if you have good XSDs.

like image 123
dave_p23 Avatar answered Jan 02 '23 18:01

dave_p23


You can, indeed, do this, via jsr-303 xml configuration. See, for example, http://www.aviyehuda.com/2010/04/using-hibernate-validator-to-cover-your-validation-needs/.

like image 21
schnitz Avatar answered Jan 02 '23 20:01

schnitz