简体   繁体   English

如何在JAXB中映射已经存在的Java bean

[英]How to map already existing java bean in JAXB

Castor framework (xml to java bean binder framework) provides functionality to map my existing java bean to xml. Castor框架(从XML到Java Bean绑定程序框架)提供了将我现有的Java Bean映射到xml的功能。 Can I achieve same thing using JAXB ? 我可以使用JAXB实现相同的功能吗?

JAXB can also be used to map existing beans to xml. JAXB还可以用于将现有bean映射到xml。 For this purpose exists the schemagen tool (also part of the JDK, at least in JDK 6) and the JAXB annotations defined in the javax.xml.bind.annotations can be used to customize the mappings. 为此,存在schemagen工具(至少在JDK 6中也是JDK的一部分),并且javax.xml.bind.annotations中定义的JAXB注释可用于自定义映射。

Depending on your requirements and existing code this might be more or less painful. 根据您的要求和现有代码,这可能会或多或少地令人痛苦。

JAXB really works the other way round. JAXB确实可以反过来工作。 Given an xsd, JAXB will generate a set of java objects reflecting the structure. 给定一个xsd,JAXB将生成一组反映该结构的java对象。 Its not always easy to represent the structure of your POJOs in the form of an XSD. 以XSD的形式表示POJO的结构并不总是那么容易。 For your task I would suggest you use JIBX since this provides much finer control over how the individual xml entities are mapped to your Java objects 对于您的任务,我建议您使用JIBX,因为这样可以更好地控制各个xml实体如何映射到Java对象

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

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