Here is what I want to do:
Give a Jaxb2Marshaller a list of schemas, have it validate a object against any one of those schemas, and pass validation of and pass validation if it is in compliance with one-and-only-one of the listed schema.
Here is what I've tried:
I have a group of JAXB classes all.my.jaxb.classes.are.here.A, all.my.jaxb.classes.are.here.B, and I have a Jaxb2Marshaller:
And this is how it fails to do what I want it to do:Code:<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller" p:packagesToScan="all.my.jaxb.classes.are.here" p:validationEventHandler-ref="vailidateEventHandler" p:marshallerListener-ref="marshallerListener"> <property name="schemas"> <list> <value>A.xsd</value> <value>B.xsd</value> </list> </property> </bean>
If I 'disable' validation then the jaxb2Marshaller doesn't throw errors, and all the classes can be marshaled.
If I marshal an A, where A is the root element of the A JAXB class, then the jaxb2Marshaller is will marshal it successfully if there aren't any validation errors, or send any validation errors to the vailidateEventHandler.
The problem is that if I try to marshal B, where B is the root element of the B JAXB class, it always complains with
If I move the B.xsd to the first entry in the schemas list, then I don't get a validation error for B, but A now encounters the validation error complaining that it can't find the root element for A.Code:severity=FATAL_ERROR,message=cvc-elt.1: Cannot find the declaration of element 'B'.,locator=[url=null,line=-1,column=-1,node=null,object=all.my.jaxb.classes.are.here.B@1c958af,field=null]]
Q. Is there a way to do what I've described above with one marshaller? I don't want to have beaucoup marshallers, because I want to use just one marshaller and one RestTemplate.
Q. If you can't do what I've described here, then what is the purpose of the schemas property?


Reply With Quote
