Why I got an exception when I try to jaxbUnmarshaller.unmarshal

Steffen Stamprath June 23, 2022

I have a groovy script using in script runner. I try to map an XML file to my model classes. But I git this exception. Anybody an Idea why?

javax.xml.bind.JAXBException  - with linked exception: [com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions groovy.lang.MetaClass ist eine Schnittstelle, und JAXB kann keine Schnittstellen verarbeiten. this problem is related to the following location: at groovy.lang.MetaClass at public groovy.lang.MetaClass Persons.getMetaClass() at Persons ]"

 

JIRA 8.20.5

 

The exception comes direct by the first line when I create the JAXBContext:

JAXBContext jaxbContext = JAXBContext.newInstance(Persons.class)

 

Her the model files

import javax.xml.bind.annotation.XmlAccessType
import javax.xml.bind.annotation.XmlAccessorType
import javax.xml.bind.annotation.XmlElement
import javax.xml.bind.annotation.XmlRootElement

@XmlRootElement(name = "persons")
@XmlAccessorType(XmlAccessType.FIELD)
class Persons {
@XmlElement(name = "persons")
private ArrayList<Person> persons = new ArrayList<Person>()

List<Person> getPersons() {
return persons
}

void setPersons(List<Person> persons) {
this.persons = persons
}
}

package com.schwermetall.buildingSecurity.dexicon.models

import javax.xml.bind.annotation.XmlAccessType
import javax.xml.bind.annotation.XmlAccessorType
import javax.xml.bind.annotation.XmlElement

@XmlAccessorType(XmlAccessType.FIELD)
class Person {
@XmlElement(name = "id")
String id
@XmlElement(name = "name")
String name
}

 

Her the XML

<?xml version="1.0" encoding="UTF-8"?>
<persons>
<person>
<id>100</id>
<name>Max Mustermann</name>
</person>
<person>
<id>200</id>
<name>Peter Peterson</name>
</person>
</persons>
 

 

1 answer

1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 25, 2022

I don't have experience with this.

But I found this https://stackoverflow.com/questions/1161147/how-do-i-get-groovy-and-jaxb-to-play-nice-together

I tried some sample code and couldn't get it to work either. Could be the way groovy is implemented in scriptrunner doesn't quite allow using JAXB

Steffen Stamprath June 28, 2022

ok, that's not satisfying, but thanks anyway!

Suggest an answer

Log in or Sign up to answer