How can I ignore a superclass?

java, jax-ws, jaxb

Solution

You need to mark the parent class @XmlTransient. Since the parent class is in the JRE and cannot be modified by you, you need an alternate mechanism.

The EclipseLink JAXB (MOXy) implementation offers a means of representing the metadata as XML that you could use:

http://wiki.eclipse.org/EclipseLink/Examples/MOXy/EclipseLink-OXM.XML

You can specify some of the metadata using annotations, and the rest as XML. Below is what your document would look like:

<java-types> 

    <java-type name="java.util.logging.LogRecord" xml-transient="true"/>

</java-types>

Problem

I'm trying to write a web service for the `java.util.logging` api. So I wrote a class MyLogRecord that inherits from LogRecord. I annotated this class with JAX-B annotations, including `@XmlAccessorType(XmlAccessType.NONE)` so it would ignore non-annotated fields and properties. When I start up tomcat, I get errors that `java.util.logging.Level` and other `java.util.logging` classes do not have a default constructor, but none of my annotated methods make any reference to the Level class or any of the other `java.util.logging` classes. These are referenced by the parent class. My sub-class has everything it needs defined. How can I get JAX-B to ignore the parent class completely? Update: I found another post on this, which suggests modifying the parent class. This is obviously not possible because I am extending a `java.util` class. IS there any way to do this without modifying the superclass? Update2: I found a thread on java.net for a similar problem. That thread resulted in an enhancement request, which was marked as a duplicate of another issue, which resulted in the `@XmlTransient` annotation. The comments on these bug reports lead me to believe this is impossible in the current spec.

Original source