¿Cómo consigo que Groovy y JAXB jueguen bien juntos?
Estoy tratando de hacer que JAXB trabaje con una clase mía maravillosa, sin embargo, parece que no funciona pero la versión de Java sí lo hace. Aquí está el código ...
Aquí están los escenarios:
Si 2 y 3 están sin comentar, funciona bien.
Si 1 y 4 no están comentados obtengo:
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException:
2 counts of IllegalAnnotationExceptions
groovy.lang.MetaClass is an interface, and JAXB can't handle interfaces.
Si 1 y 5 no están comentados obtengo:
javax.xml.bind.JAXBException: class org.oclc.presentations.simplejaxb.PlayerGroovy
nor any of its super class is known to this context.
¿Algunas ideas?
Java:
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Player {
}
Maravilloso
import javax.xml.bind.annotation.XmlRootElement
@XmlRootElement
public class PlayerGroovy {
}
Prueba:
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)
}
}