我怎样才能忽略超类? [英] How can I ignore a superclass?

查看:18
本文介绍了我怎样才能忽略超类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 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?

更新:我发现 another post on this,建议修改父类.这显然是不可能的,因为我正在扩展一个 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 上找到 一个线程 类似的问题.该线程产生了一个增强请求,它被标记为another issue 的副本,导致 @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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆