jaxb-ri
jaxb-ri copied to clipboard
Unmarshaller does not use results of validation
As a work-around for issue https://jaxb.dev.java.net/issues/show_bug.cgi?id=515, I instructed the unmarshaller to use validation ( using setSchema() ), hoping that the validation process enhances the xml content with the missing fixed (or default) attribute values. This does not work, because internally, the validation and unmarshalling pipes are parallel instead of sequential (see com.sun.xml.bind.v2.runtime.unmarshaller.ValidationUnmarshaller).
If i set up the sax-streams manually, connecting the output of validation to the unmarshaller, the enhancement does work:
InputStream xmlStream = ... Source xmlSource = new StreamSource(xmlStream); JAXBContext ctx = ... Schema schema = ...
UnmarshallerHandler uh = ctx.createUnmarshaller().getUnmarshallerHandler(); ValidatorHandler vh = schema.newValidatorHandler(); // send output of validation to the jaxb unmarshaller vh.setContentHandler(uh);
TransformerFactory tf = TransformerFactory.newInstance(); // use an identity transformation to stream to the validating handler tf.newTransformer().transform( xmlSource , new SAXResult(vh));
JAXBElement> result = (JAXBElement>) uh.getResult();
Could the com.sun.xml.bind.v2.runtime.unmarshaller.ValidationUnmarshaller be modified to use the output of validation as input for the unmarshalling?
Environment
Operating System: All Platform: All
Affected Versions
[2.1.6]
- Issue Imported From: https://github.com/javaee/jaxb-v2/issues/683
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @glassfishrobot
@glassfishrobot Commented Reported by tdesmedt
@glassfishrobot Commented snajper said: Interesting idea. Perhaps we could come up with a property for this?
@glassfishrobot Commented Was assigned to snajper
@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-683