Home > Enterprise >  JAXB Spring Boot JaxbContextContainer and Kotlin data class no arg constructor
JAXB Spring Boot JaxbContextContainer and Kotlin data class no arg constructor

Time:11-28

I have a data class that is XmlRootElement:

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

@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
data class Rss(
    @field:XmlElement
    val channel: Channel
)

When my WebClient tries to deserialize RSS feed I get:

Caused by: org.glassfish.jaxb.runtime.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
com.example.rss.model.Rss does not have a no-arg default constructor.
    this problem is related to the following location:
        at com.example.rss.model.Rss

CodePudding user response:

You can use no-arg compiler plugin. It will generate an additional zero-argument constructor for the class with a specific annotation. I think in your case @XmlRootElement is a good candidate.

It is easily configured within Maven or Gradle.

Docs on how to configure it -> https://kotlinlang.org/docs/no-arg-plugin.html

  • Related