1

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

lexicore
  • 42,748
  • 17
  • 132
  • 221
RenHoek
  • 75
  • 1
  • 1
  • 4

1 Answers1

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.

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • 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