Does @XmlRootElement requires namespace? I think Jaxb generation should create package-info.java with @javax.xml.bind.annotation.XmlSchema(namespace ...
And btw, Jettison has array serialization issue bug, where "single item" arrays serialized without [] I think better way, if you require xsd validation, use moxy json provider, or wait for JSR303 validation switch for wadl2java. 2016-08-26 12:32 GMT+04:00 J. Fiala <mod...@fwd.at>: > Hi, > > I'd like to add schema validation for Json requests (as described in > https://cwiki.apache.org/confluence/display/CXF20DOC/JAX-RS+ > Data+Bindings#JAX-RSDataBindings-Schemavalidation). > > 1.) Schemavalidation using Json JacksonProvider / JAXBElementProvider: > Configuration used: > > <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.pr > ovider.JAXBElementProvider"> > <property name="schemaHandler" ref="schemaHolder"/> > </bean> > > <bean id="schemaHolder" class="org.apache.cxf.jaxrs.ut > ils.schemas.SchemaHandler"> > <property name="schemas" ref="theSchemas"/> > </bean> > > <util:list id="theSchemas"> > <value>my_complex_types_and_elements.xsd</value> > </util:list> > > I'm sending an invalid JSON which does not match the defined pattern, but > the validation doesn't strike. > > The only message I see in the log is: > o.apache.cxf.jaxrs.utils.ResourceUtils : No resource > classpath:META-INF/jax-rs-catalog.xml is available > > Is there anything else I have to set to activate schema validation? > > Or is the JAXBElementProvider only active for XML request processing and > schema validation is not possible using JacksonProvider ? > > 2.) jettison/org.apache.cxf.jaxrs.provider.json.JSONProvider > > When I try to use jettison/org.apache.cxf.jaxrs.provider.json.JSONProvider > and add the schemaHandler: > > <bean id="jsonProvider" class="org.apache.cxf.jaxrs.pr > ovider.json.JSONProvider"> > <property name="schemaHandler" ref="schemaHolder"/> > </bean> > > Then I get with the first attempt (model generated using wadl2java): > Caused by: com.sun.istack.internal.SAXException2: unable to marshal type > "..." as an element because it is missing an @XmlRootElement annotation > > After adding @XmlRootElement(namespace="|http://www.example.org/books|"), > the exception changes: > Payload: JAXBException occurred : cvc-elt.1: Cannot find the declaration > of element "..." > > The Json request sent using the CXF client includes a namespace prefix: > {"ns2:myRequestType":{...}} > > If I remove the namespace prefix, the error stays the same: > {"myRequestType":{...}} > > Next I thought to add a jsonNamespaceMap (as described here > http://cxf.apache.org/docs/jax-rs-data-bindings.html): > > <bean id="jsonProvider" class="org.apache.cxf.jaxrs.pr > ovider.json.JSONProvider"> > <property name="schemaHandler" ref="schemaHolder"/> > <property name="namespaceMap" ref="jsonNamespaceMap"/> > </bean> > > |<||util:map| |id||=||"jsonNamespaceMap"| |map-class||=||"java.util.Hash > table"||>| > |<||entry| |key||=||"http://www.example.org/books"| |value||=||"ns2"||/>| > |</||util:map||> > But still no luck, the error stays the same, regardless if the Json > includes the prefix or not. > | > > Any ideas on this? > > best regards, > > Johannes > >