jaxb-ri icon indicating copy to clipboard operation
jaxb-ri copied to clipboard

Unmarshaller does not use results of validation

Open Tomas-Kraus opened this issue 15 years ago • 5 comments

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]

Tomas-Kraus avatar Aug 31 '09 01:08 Tomas-Kraus

  • Issue Imported From: https://github.com/javaee/jaxb-v2/issues/683
  • Original Issue Raised By:@glassfishrobot
  • Original Issue Assigned To: @glassfishrobot

Tomas-Kraus avatar Sep 21 '18 15:09 Tomas-Kraus

@glassfishrobot Commented Reported by tdesmedt

Tomas-Kraus avatar Aug 31 '09 01:08 Tomas-Kraus

@glassfishrobot Commented snajper said: Interesting idea. Perhaps we could come up with a property for this?

Tomas-Kraus avatar Sep 11 '09 10:09 Tomas-Kraus

@glassfishrobot Commented Was assigned to snajper

Tomas-Kraus avatar Aug 31 '09 01:08 Tomas-Kraus

@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-683

Tomas-Kraus avatar Apr 24 '17 12:04 Tomas-Kraus