Quantcast
Channel: Thorsten Maier – techscouting through the java news
Viewing all articles
Browse latest Browse all 44

JAXB und Groovy

$
0
0

Soll die Instanz einer solchen Groovy-Klasse mit Hilfe von JAXB als XML gespeichert werden, schlägt dies mit der folgenden Fehlermeldung fehl:

groovy.lang.MetaClass is an interface, and JAXB can't handle interfaces.

JAXB ist also nicht in der Lage, das Attribut “metaClass”, das in jeder Groovy-Klasse zur Verfügung steht,  zu persistieren. Daher muss in Groovy die automatische Attributerkennung von JAXB deaktiviert und alle Attribute manuell per Annotation bekannt gemacht werden:

@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement
public class Entity {
  @XmlAttribute
  String value
}

Durch die Annotation @XmlAccessorType(XmlAccessType.NONE) wird die automatische Erkennung deaktiviert. Das Attribut value wird anschließend mit Hilfe der Annotation @XmlAttribute für JAXB markiert.


Einsortiert unter:Groovy and Grails, Java Persistence, XML Universe Tagged: annotation, JAXB, XML Universe

Viewing all articles
Browse latest Browse all 44

Trending Articles