JAXB自动生成的类层次结构

编程入门 行业动态 更新时间:2024-10-20 21:02:11
本文介绍了JAXB自动生成的类层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在基于各种WSDL生成Java代码。对于我们发布的每个新版本的WebService,我们都有一个不同的WSDL,每个版本都有其自己的命名空间。

I'm generating java code based on various WSDL's. We have a different WSDL for every new version of the WebService that we release, each with its own namespace.

通常,从一个发行版到发行版之间的更改通常很小

The thing is that normally the changes are minimal from one release to another, but I want to keep classes divided by namespace.

是否可以配置JAXB,以便自动生成的类实现单个接口/扩展单个类,

Is there a way to configure JAXB so that the auto generated classes implement a single interface/extend a single class, so I can refer to either of them without changing my code?

虚拟示例:

WebService方法: listScripts(ResultSize size);

WebService method: listScripts(ResultSize size);

自动生成的类:

  • com.test.ws1.ResultSize
  • com.test。 ws2.ResultSize
  • com.test.ws1.ResultSize
  • com.test.ws2.ResultSize

两个类完全相同。有没有一种方法可以将它们排列在类层次结构中,从而使我的代码与版本号的更改隔离开?即两个类都实现的 com.test.ResultSize 接口?

Both classes are exactly the same. Is there a way to arrange them in a class hierarchy so my code is isolated from changes in version numbers? i.e. a com.test.ResultSize interface implemented by both classes?

推荐答案

事实证明,我可以使用JAXB2 Basics软件包中提供的插件:

It turned out that I can use a plugin provided in the JAXB2 Basics package:

继承插件

通过该插件,我可以为生成的类指定不同的超类,尽管我不能

With this plugin I can specify different super classes for my generated ones, although I couldn't make the auto generated enums to implement a given interface.

要在Maven中使用它,这很痛苦(我是从WSDL生成类,而不是直接使用JAXB) ),因此我按照此博客

To use it in Maven it was a pain (I'm generating classes from a WSDL, not using JAXB directly), so I switched to an external Ant task as specified in this blog

更多推荐

JAXB自动生成的类层次结构

本文发布于:2023-11-29 16:49:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自动生成   层次   结构   JAXB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!