pichsenmeister
pichsenmeister

Reputation: 2132

Scala JAXB 1 counts of IllegalAnnotationExceptions

I have two Scala case classes, which have JAXB annotations.

@XmlRootElement
@XmlSeeAlso({ Array(classOf[Element]) })
case class Config(
    @(XmlElement @field) name: String,
    @(XmlElement @field) reelCount: Int,
    @(XmlElement @field) slots: Int,
    @(XmlElementWrapper @field)@(XmlAnyElement @field) elements: List[Element]) {
    private def this() = this("", 0, 0, new ArrayList())
}

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
case class Element(
    @(XmlAttribute @field)@(XmlID @field) id: Int,
    @(XmlElement @field) name: String,
    @(XmlElement @field) imgPath: String) {
    private def this() = this(0, "", "")
}

The marshalling works, when I remove the @(XmlID @field) annotation from the first attribute of the Element. When I annotate it with the xml id field, I get following exception:

[IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions]

It should work in Java with this 2 annotations, but no idea what I'm doing wrong in Scala. Any ideas? Or maybe some workaround?

Upvotes: 2

Views: 2162

Answers (1)

bdoughan
bdoughan

Reputation: 149047

The JAXB (JSR-222) reference implementation only allows the @XmlID annotation on fields/properties on type String. This is why you are getting an IllegalAnnotationsException on your field of type Int.

Upvotes: 1

Related Questions