You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by obesga <ob...@tirant.com> on 2016/07/22 17:17:30 UTC

Can not use JAXB into a groovy script

Hi, fellow groovylanders


I have  a problem with groovy scripts, JAXB marshaller and I think it is the classloader of groovy scripts
But no problem executing this code into a groovy class (with a main launcher)  

The code is here
try {

    StringReader stringReader = new StringReader(dataa);
    JAXBContext jaxbContextRespuesta = JAXBContext.newInstance(MensajeWS.class)
    Unmarshaller unmarshallerRespuesta = jaxbContextRespuesta.createUnmarshaller();
    MensajeWS mensajeWSRespuesta = (MensajeWS) unmarshallerRespuesta.unmarshal(stringReader)


    println mensajeWSRespuesta;
} catch(Exception e) {
    println e
    e.printStackTrace()
}

The exception is this
java.lang.NullPointerException
	at javax.xml.bind.ContextFinder.handleClassCastException(ContextFinder.java:129)
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:265)
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:249)
	at javax.xml.bind.ContextFinder.find(ContextFinder.java:477)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:656)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:599)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46)
	at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:91)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
	at mejor_no_ejecutar_esto.run(mejor_no_ejecutar esto.groovy:65)
	at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)


I’m using IntelliJIdea to launch it
- when launched as groovy mean class - java standard it goes ok
- when launched as groovy script, error is thrown

I think it’s a class loader problem, but after searching on the web (like stack overflow) I’m out of ideas

Anyone has a similar problem ?

Thanks

Oscar Besga
obesga@tirant.com