简体   繁体   English

将JAXB批注应用于现有数据模型

[英]apply JAXB annotation to an existing data model

I have the following problem. 我有以下问题。 For webservices I am using an existing data model. 对于Web服务,我正在使用现有的数据模型。 So I need to apply JAXB annotations on the existing source classes. 因此,我需要在现有的源类上应用JAXB批注。 This requires a lot of effort to do manually. 这需要手动进行大量的工作。

Does anyone know a tool that can help automate this process? 有谁知道可以帮助自动化此过程的工具? For clarity, generating java source code through an xsd is not the goal. 为了清楚起见,通过xsd生成Java源代码不是目标。

You can first get all classes in your data model package and then use Javassist to do add an annotation on each of those classes at run-time. 您可以首先在数据模型包中获取所有类,然后在运行时使用Javassist在每个这些类上添加注释。

  • Check out how to get all classes in a package tutorial 在软件包教程中查看如何获取所有类
  • Check out this Javassist tutorial about adding annotations at runtime 查看有关在运行时添加注释的Javassist 教程

If you want to avoid this procedure though and just change the source code I think Search/Replace in your data model package would be the way to go. 但是,如果您想避免执行此过程,而只是更改源代码,那么我认为在数据模型包中进行“搜索/替换”将是您的最佳选择。

JAXB (JSR-222) is configuration by exception. JAXB(JSR-222)是例外配置。 This means you only need to annotate the model where the desired representation defers from the default one: 这意味着您只需要注释模型,其中所需的表示形式会偏离默认模型:

If you have an XML Schema that you are trying to map your domain model to, then you may find the Dali JAXB tooling in Eclipse helpful. 如果您尝试将域模型映射到XML模式,那么您可能会发现Eclipse中Dali JAXB工具很有帮助。 I would recommend trying out a pre-released version of Juno. 我建议尝试使用Juno的预发行版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM