Note that there are some explanatory texts on larger screens.

plurals
  1. POJAX-RS: Request validation using XSD, JAXB
    primarykey
    data
    text
    <p><strong>Tech Stack</strong>: Java 1.6, JAXB, Spring 3, JAX-RS (RESTEasy)</p> <p>I've written a web service (REST) and now I want to validate the request using a schema. I've a working code as seen <a href="https://stackoverflow.com/questions/3428273/validate-jaxbelement-in-jpa-jax-rs-web-service/3440388#3440388">here</a> for validation.</p> <p>My code looks like this:</p> <pre><code>public abstract class AbstractValidatingReader&lt;T&gt; implements MessageBodyReader&lt;T&gt; { @Context protected Providers providers; private Schema schema; public AbstractValidatingReader() { .... } @SuppressWarnings("unchecked") @Override public boolean isReadable(Class&lt;?&gt; arg0, Type arg1, Annotation[] arg2, MediaType arg3) { .... return arg0 == readableClass; } @SuppressWarnings("unchecked") @Override public T readFrom(Class&lt;T&gt; arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap&lt;String, String&gt; arg4, ..... return type; } protected abstract T validate(T arg0) throws WebApplicationException; } </code></pre> <p>and,</p> <pre><code>@Component @Provider @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_XAMF }) public class ValidatingReaderImpl extends AbstractValidatingReader&lt;Person&gt; { @Override protected Person validate(Person arg0) throws WebApplicationException { return arg0; } } </code></pre> <p>This works fine for <strong>Person</strong> class and the request is getting validated. But, I've many other requests e.g. Contacts, Links, Employment etc.</p> <p><em>Do I have to extend the AbstractValidatingReader class for each request type?</em></p> <p>I am <strong>validating against the same schema</strong>, so looks like lot of code\classes for doing this.</p> <p>Thanks, Adi</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload