简体   繁体   中英

apply JAXB annotation to an existing data model

I have the following problem. For webservices I am using an existing data model. So I need to apply JAXB annotations on the existing source classes. 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.

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.

  • Check out how to get all classes in a package tutorial
  • Check out this Javassist tutorial about adding annotations at runtime

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. 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. I would recommend trying out a pre-released version of Juno.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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