0
我想知道是否有一种方法可以动态地将任何Java对象转换为另一种使用注释或XML配置来定义映射。如何将任何Java对象动态转换为另一个?
我听说Apache的PropertyUtils
提供了一种在Java对象之间来回复制数据的方法,并且类型转换由ConvertUtils
处理,这将需要我自己定制的Converter。
例如:
class A {
long sellerId;
long buyerId;
String orderId;
Date purchaseDate;
//getter and setters
}
------------------------------------------------------------------------
class B {
Integer payerId; //mapped to buyerId
Integer payeeId; //mapped to sellerId
String externalId //mapped to orderId
Calendar tranDate; //mapped to purchase Date
//getter and setters
}
请让我知道,如果有一个开源的组件,它会使用反射,注释或XML配置提供了动态的Java类型转换?
任何帮助表示赞赏!
你可以尝试用伪代码表达你如何使这个库的功能? – 2012-04-14 20:35:19
你能举两个你想转换的类的例子吗? – 2012-04-14 20:36:31