JAXB和类实例化 [英] JAXB and class instantiation

查看:56
本文介绍了JAXB和类实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一件事阻止使用像JAXB这样的绑定技术,而不是经典的基于dom / sax的xml技术,这个事实是,当读取xml时,它似乎强烈地面向实例化它管理的类。

One thing that prevents from using a binding technology like JAXB, instead of a classic dom/sax-based xml technology is the fact that, when reading xml, it seems to be strongly oriented to instantiate the classes that it manages.

很多时候,我想从xml读取值并将它们设置为已创建实例的属性。

有没有一种简单的方法告诉JAXB它必须将值应用于我所拥有的类而不是创建一个新的?

Many times, i want to read values from xml and set them to properties of already created instances.
Is there a simple way to tell JAXB that it has to apply values to the class that i have instead of create a new one?

推荐答案

将JAXB对象用作DTO。然后你可以使用 PropertyUtils.copyProperties(..) / BeanUtils.copyProperties(..)(来自commons-beanutils )将属性传输到已经部分填充的对象。

Use the JAXB objects as DTOs. Then you can use PropertyUtils.copyProperties(..) / BeanUtils.copyProperties(..) (from commons-beanutils) to transfer the properties to your already-partially-populated objects.

这篇关于JAXB和类实例化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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