Eurofiling jaxb2 collision

35 Views Asked by At

Eurofiling updated their schema-File to Version 2.0. I am trying to generate java code with the maven plugin "jaxb2-maven-plugin". This worked fine for the previous version.

Here is the file: http://www.eurofiling.info/eu/fr/xbrl/ext/model.xsd

With version 2.0.0 there is a name clash:

com.sun.istack.SAXParseException2: Two declarations cause a collision in the ObjectFactory class.
<element name="null-dimension" type="xbrli:stringItemType" abstract="true" substitutionGroup="xbrldt:dimensionItem" xbrli:periodType="instant" nillable="true" model:fromDate="2016-01-01" model:creationDate="2016-01-01" id="null-dimension"/>

<element name="NullDimension" type="xbrli:stringItemType" abstract="true" substitutionGroup="xbrldt:dimensionItem" xbrli:periodType="instant" nillable="true" model:fromDate="2023-01-01" model:creationDate="2023-10-17" id="NullDimension"/>

I tried to avoid the clash by renaming:

<bindings schemaLocation="http://www.eurofiling.info/eu/fr/xbrl/ext/model.xsd" version="1.0">
    <bindings node="//xs:schema//xs:element[@name='NullDimension']">
      <property name="nullDimension2"/>
    </bindings>
  </bindings>

But I get the following error:

com.sun.istack.SAXParseException2: compiler was unable to honor this property customization. It is attached to a wrong place, or its inconsistent with other bindings.

Edit: jaxb2-maven-plugin configuration

<configuration>
  <sources>
    <source>...</source>
  </sources>
  <locale>en</locale>
</configuration>
1

There are 1 best solutions below

0
Laurent Schoelens On BEST ANSWER

The error you're getting is

Two declarations cause a collision in the ObjectFactory class.

This error is well caused by the two elements pointed above null-dimension and NullDimension

To fix this, the good binding is not to use the <jaxb:property name="XXX" /> which fixes error of the following type :

Property "{0}" is already defined. Use <jaxb:property> to resolve this conflict.`

You need to use the following binding (adaptation of yours)

<bindings schemaLocation="http://www.eurofiling.info/eu/fr/xbrl/ext/model.xsd" version="1.0">
  <bindings node="//xs:schema//xs:element[@name='NullDimension']">
    <factoryMethod name="NullDimension2" /> <!-- or whatever name you want to avoid the conflict -->
  </bindings>
</bindings>

It will generate the following in the ObjectFactory class

    @XmlElementDecl(namespace = "http://www.eurofiling.info/xbrl/ext/model", name = "null-dimension", substitutionHeadNamespace = "http://xbrl.org/2005/xbrldt", substitutionHeadName = "dimensionItem")
    public JAXBElement<StringItemType> createNullDimension(StringItemType value) {
        return new JAXBElement<>(_NullDimension_QNAME, StringItemType.class, null, value);
    }

    @XmlElementDecl(namespace = "http://www.eurofiling.info/xbrl/ext/model", name = "NullDimension", substitutionHeadNamespace = "http://xbrl.org/2005/xbrldt", substitutionHeadName = "dimensionItem")
    public JAXBElement<StringItemType> createNullDimension2(StringItemType value) {
        return new JAXBElement<>(_NullDimensionType_QNAME, StringItemType.class, null, value);
    }