Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [Moxy] setValidating is throwing an exception when used on DynamicContext
[Moxy] setValidating is throwing an exception when used on DynamicContext [message #1704075] Fri, 07 August 2015 08:09
Paweł Englert is currently offline Paweł EnglertFriend
Messages: 8
Registered: November 2014
Junior Member
Hi there,

I was using Dynamic context and trying to turn on validation. I found some difficulties:

- I need to provide schema to create dynamic context, why is it also needed to provide schema once again to unmarshaller? Schema shouldn't be there by design?
- When i was tryign to setSchema() on unmarshaller and then setValidation(true) it is throwing an expection.

Sample code
DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromXSD(streamSource, null, null, null);
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(streamSource2);
        final JAXBUnmarshaller unmarshaller = jaxbContext .createUnmarshaller();

 unmarshaller.setSchema(schema);
 unmarshaller.setValidating(true);


gives an Exception:
Exception Description: An error occurred resolving the XML Schema.
Internal Exception: java.lang.NullPointerException
Exception [EclipseLink-25012] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: An error occurred resolving the XML Schema.
Internal Exception: java.lang.NullPointerException
    at org.eclipse.persistence.exceptions.XMLMarshalException.errorResolvingXMLSchema(XMLMarshalException.java:186)
    at org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference.getURL(XMLSchemaClassPathReference.java:48)
    at org.eclipse.persistence.oxm.XMLUnmarshaller.initializeSchemas(XMLUnmarshaller.java:211)
    at org.eclipse.persistence.oxm.XMLUnmarshaller.setValidationMode(XMLUnmarshaller.java:155)
    at org.eclipse.persistence.jaxb.JAXBUnmarshaller.setValidating(JAXBUnmarshaller.java:756)



I found workaround, but it should be handled properly without such hacks.

        int numberOfSessions = ((XMLContext) jaxbContext.getXMLContext()).getSessions().size();
        for (int x = 0; x < numberOfSessions; x++) {
            final Collection values = ((CoreSession) jaxbContext.getXMLContext().getSessions().get(x)).getDescriptors().values();

            List<XMLDescriptor> proper = new LinkedList<>();
            URL schemaURL;
            final Iterator iterator = values.iterator();
            while (iterator.hasNext()) {
                final XMLDescriptor xmlDescriptor = (XMLDescriptor) iterator.next();
                final XMLSchemaReference schemaReference = xmlDescriptor.getSchemaReference();

                if (schemaReference.getResource() == null) {
                    log.info("{}", ToStringBuilder.reflectionToString(schemaReference, ToStringStyle.DEFAULT_STYLE, true));


                    XMLSchemaFileReference xmlSchemaFileReference = new XMLSchemaFileReference(xsd);
                    xmlSchemaFileReference.setSchemaContext(schemaReference.getSchemaContext());
                    xmlSchemaFileReference.setSchemaContextAsQName(schemaReference.getSchemaContextAsQName());
                    xmlSchemaFileReference.setType(schemaReference.getType());
                    xmlDescriptor.setSchemaReference(xmlSchemaFileReference);
                }

            }
        }

[Updated on: Fri, 07 August 2015 08:10]

Report message to a moderator

Previous Topic:[Moxy] json marshalling, mixed element unexpected behaviour
Next Topic:NoSuchMethodError due to EclipseLink internal weaving?
Goto Forum:
  


Current Time: Sat Mar 06 18:08:14 GMT 2021

Powered by FUDForum. Page generated in 0.01591 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top