For a REST-Webservice i had to validate incoming Data. Is is possible to validate incoming data with an Entity Class and JAXB , instead of xsd
Asked
Active
Viewed 891 times
1 Answers
0
Below is a link of how you could validate Data in a JAX-RS service using JAXB validation based on a schema:
If you don't have an XML schema from your model, then you could use JAXB to generate one:
If you wanted to do validation without an XML schema you could use something like Bean Validation (JSR-303). With this you would still need to implement a custom MessageBodyReader
/MessageBodyWriter
.
-
It would be really cool to have JSR-303 validation annotation from the XML Schema. – lexicore Jun 03 '11 at 21:44
-
It would be great, if teher is an Possibility to use my EntityClass and the JAXB Un-/Marshaller Class in combination. With XmlRootElement(name="rootelement") and @XmlElement(name="child") i have all the properties i need. How do i validate my Incoming data against the element naming ? – RenHoek Jun 04 '11 at 12:54
-
@RenHoek - You could use JAXB to generate the schema based on your mappings (http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JAXB/GenerateSchema). Then you could set it on the Unmarshaller to do the validation. – bdoughan Jun 06 '11 at 16:51
-
okay, i am stucking... how is it possible to Overwrite the MessageBodyReader in Jersey ? Has to be in the Service class for a ressource ? .... – RenHoek Jun 07 '11 at 15:32
-
@RenHoek - The following should help: http://stackoverflow.com/questions/3428273/validate-jaxbelement-in-jpa-jax-rs-web-service/3440388#3440388 – bdoughan Jun 07 '11 at 15:33
-
okay... i was to blind. i have to Implemented for the ResourceService ... Thanks a lot – RenHoek Jun 07 '11 at 16:02