Kotlin - JAXB unmarshalling leads to error

32 views Asked by At

I got big problems while unmarshalling. I generated with xjc data classes from my xsd file. This seems to work without any problem.

Now I tried this in my Kotlin project

val jaxbContext = JAXBContext.newInstance("org.inek.xml.schema.standortverzeichnis")//.newInstance(Standortverzeichnis::class.java)
val unmarshaller = jaxbContext.createUnmarshaller()

when I run the code I got following error message:

Exception in thread "main" javax.xml.bind.JAXBException: "org.inek.xml.schema.standortverzeichnis" does not contain ObjectFactory.class or jaxb.index

I don't know whats wrong with the code. The export from xjc is located in the same directory like the main.kt. The directory is named "org.inek.xml.schema.standortverzeichnis". The directory contains all data classes including ObjectFactroy and package-info.java

Thanks for help

1

There are 1 answers

0
Laurent Schoelens On

Whether specified by the tool used or derived from namespace declared in XSD, generating java classes from XSD should generate classes in a base package with an ObjectFactory class in it.

For example, having the targetNamespace declared as targetNamespace="http://po.example.org", it will generate java classes like here

Then, in my code (here kotlin syntax, but Java should be the same), I'll instantiate the jaxbContext by refering the base package org.example.po, containing the ObjectFactory class in it

val jaxbContext = JAXBContext.newInstance("org.example.po")

You can then adapt this sample to your code to find the best package to instantiate your JAXBContext

Regards,

Laurent