Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get Groovy and JAXB to play nice together
    text
    copied!<p>I am trying to get JAXB to work with a groovy class of mine, however, it appears it doesn't work but the java version does. Here is the code...</p> <p>Here are the Scenarios:</p> <p>If 2 and 3 are uncommented it works fine.</p> <p>If 1 and 4 are uncommented I get:</p> <pre><code> com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions groovy.lang.MetaClass is an interface, and JAXB can't handle interfaces. </code></pre> <p>If 1 and 5 are uncommented I get:</p> <pre><code> javax.xml.bind.JAXBException: class org.oclc.presentations.simplejaxb.PlayerGroovy nor any of its super class is known to this context. </code></pre> <p>Any ideas?</p> <p>Java:</p> <pre><code> import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Player { } </code></pre> <p>Groovy:</p> <pre><code> import javax.xml.bind.annotation.XmlRootElement @XmlRootElement public class PlayerGroovy { } </code></pre> <p>Test:</p> <pre><code> import org.junit.Test import javax.xml.bind.JAXBContext import javax.xml.bind.Marshaller import org.junit.Assert class PlayerTest { @Test public void testJaXB(){ //1 PlayerGroovy player = new PlayerGroovy() //2 Player player = new Player() StringWriter writer = new StringWriter(); //3 JAXBContext context = JAXBContext.newInstance(Player.class); //4 JAXBContext context = JAXBContext.newInstance(PlayerGroovy.class); //5 JAXBContext context = JAXBContext.newInstance(PlayerGroovy.getClass()); Marshaller m = context.createMarshaller(); m.marshal(player, writer); println(writer) Assert.assertTrue(true) } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload