Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the jaxb documented property com.sun.xml.bind.xmlHeaders is not recognized but the "internal" one does?

Tags:

jaxb

I'm confused about the JAXB 2.2.11 documentation where the property is described as com.sun.xml.bind.xmlHeaders but when I try it:

javax.xml.bind.PropertyException: name: com.sun.xml.bind.xmlHeaders

But using com.sun.xml.internal.bind.xmlHeaders (note: internal) works.

So my question is really about the rationale of this. Am I looking at the wrong documentation? Where is the internal coming from?

public static void main(String[] args) throws JAXBException {
    MyElement myxml = new MyElement();
    JAXBContext context = JAXBContext.newInstance(MyElement.class);
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    marshaller.setProperty("com.sun.xml.bind.xmlHeaders","");
    //marshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders","<DOCTYPE>");

    marshaller.marshal(myxml, System.out);
}
like image 709
RubenLaguna Avatar asked Dec 22 '17 09:12

RubenLaguna


1 Answers

Make sure that right implementation of JAXB is on the classpath. Apparently there are several "reference implementations" to choose from apart from the one shipped with the JDK.

Property: com.sun.xml.internal.bind.xmlHeaders

  • JDK 8 version
  • javax.xml.bind:jaxb-api:2.2.11

Property: com.sun.xml.bind.xmlHeaders

  • org.glassfish.jaxb:jaxb-runtime:2.2.11
  • com.sun.xmlbind:jaxb-core:2.2.11 plus com.sun.xmlbind:jaxb-impl:2.2.11

If you are using Maven:

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.2.11</version>
</dependency>

Supports com.sun.xml.bind.xmlHeaders (no internal).

Or if you use:

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.2.11</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.11</version>
</dependency>

You also get com.sun.xml.bind.xmlHeaders.

But if you use:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.11</version>
</dependency>

You only get com.sun.xml.internal.bind.xmlHeaders.

All of them are JAXB 2.2.11 but from different vendors/providers so they differ in things like the marshaller properties supported (since some of them are really not part of the JAXB specification).

like image 81
RubenLaguna Avatar answered Jan 01 '23 09:01

RubenLaguna