我如何忽略超类? [英] How can I ignore a superclass?
问题描述
我正在尝试为 java.util.logging
api编写一个Web服务。所以我编写了一个继承自LogRecord的类MyLogRecord。我使用JAX-B注释注释了这个类,包括 @XmlAccessorType(XmlAccessType.NONE)
,因此它会忽略未注释的字段和属性。当我启动tomcat时,我收到 java.util.logging.Level
和其他 java.util.logging
的错误类没有默认构造函数,但是我的注释方法都没有对Level类或任何其他 java.util.logging
类进行任何引用。这些由父类引用。
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.
我的子类具有它需要定义的所有内容。如何让JAX-B完全忽略父类?
My sub-class has everything it needs defined. How can I get JAX-B to ignore the parent class completely?
更新:我发现另一个帖子时,建议修改父类。这显然是不可能的,因为我正在扩展 java.util
类。有没有办法在不修改超类的情况下做到这一点?
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:我发现 java.net上的一个线程。该主题产生了增强请求,标记为另一个问题的副本,导致 @XmlTransient
注释。对这些错误报告的评论让我相信这在目前的规范中是不可能的。
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.
推荐答案
你需要标记父类@XmlTransient。由于父类在JRE中并且您无法修改,因此您需要一种备用机制。
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.
EclipseLink JAXB(MOXy)实现提供了一种表示元数据的方法作为您可以使用的XML:
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
您可以指定一些使用注释的元数据,其余的作为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>
这篇关于我如何忽略超类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!