Tag: apache commons beanutils

Java:合并2个“bean”以生成一个新的bean

我需要从Bean1和Bean2获取所有字段和集合,有时应用一些业务逻辑,并生成Bean3(所有bean都是具有相当复杂图形的相同类型的hibernate / domain对象)。 有关如何做到这一点的任何想法? 过去做过类似的事吗? 我的想法: 推土机(http://dozer.sourceforge.net/) BeanUtils(http://commons.apache.org/beanutils/) 手动解决方案 还有其他很酷的解决方案? 有什么建议?

是否可以使用Commons Bean Utils自动实例化嵌套属性?

我正在使用Apache Commons Bean Utils的PropertyUtils.setProperty(object,name,value)方法: 给这些课程: public class A { B b; } public class B { C c; } public class C { } 和这个: A a = new A(); C c = new C(); PropertyUtils.setProperty(a, “bc”, c); //exception 如果我尝试得到: org.apache.commons.beanutils.NestedNullException:bean类’class A ‘ 上’bc’的空属性值 是否有可能告诉PropertyUtils,如果嵌套属性具有空值,尝试在尝试深入之前实例化它(默认构造函数)? 还有其他方法吗? 谢谢

BeanUtils与ReflectionToStringBuilder的性能(用于Bean类)

我的Web应用程序中有大量的Java bean类,我试图找到一种在这些bean中实现toString()方法的简单方法。 toString()方法将用于整个应用程序的日志记录,并应打印bean中所有属性的属性值对。 我正在尝试两种选择: 1. BeanUtils.describe() (Apache commons-beanutils) 2. ReflectionToStringBuilder.toString() (Apache commons-lang) 由于这是一个预计会有高流量的Web应用程序,因此实现必须是轻量级的,不应影响性能。 (内存使用,处理器使用等是主要考虑因素)。 我想根据上面提到的标准知道哪些更好。 据我所知,reflection是一项繁重的操作,但更多细节和对这两种选项的深入了解将有助于我选择最佳解决方案。

Java Collections.sort – 帮我删除未经检查的警告

List questions = new ArrayList(); questions.addAll(getAllQuestions()); //returns a set of Questions Collections.sort(questions, new BeanComparator(“questionId”)); //org.apache.commons.beanutils.BeanComparator 在Java 1.5下,上述工作正常,只是’new BeanComparator(“questionId”)’生成一个未经检查的警告。 我不喜欢警告。 有没有办法可以为BeanComparator提供类型,还是必须使用@SuppressWarnings(“unchecked”) ?

BeanUtils copyProperties复制Arraylist

我知道BeanUtils可以将单个对象复制到其他对象。 是否可以复制一个arraylist。 例如: FromBean fromBean = new FromBean(“fromBean”, “fromBeanAProp”, “fromBeanBProp”); ToBean toBean = new ToBean(“toBean”, “toBeanBProp”, “toBeanCProp”); BeanUtils.copyProperties(toBean, fromBean); 怎么做到这一点? List fromBeanList = new ArrayList(); List toBeanList = new ArrayList(); BeanUtils.copyProperties(toBeanList , fromBeanList ); 它不适合我。 谁能帮帮我吗。 提前致谢。

BeanUtils copyProperties API忽略null和特定属性

Spring的BeanUtils.copyProperties()提供了在复制bean时忽略特定属性的选项: public static void copyProperties(Object source, Object target, String[] ignoreProperties) throws BeansException Apache Commons BeanUtils是否提供类似的function? 使用Spring的BeanUtils.copyProperties()时也可以忽略空值,我在Commons BeanUtils中看到了这个特性: Date defaultValue = null; DateConverter converter = new DateConverter(defaultValue); ConvertUtils.register(converter, Date.class); 我可以用Spring的BeanUtils实现同样的目标吗?

BeanUtils.cloneBean()深层复制

如果bean中的所有对象都实现了Serializable接口,那么BeanUtils.cloneBean()执行深层复制吗?

如何使用BeanUtils.copyProperties?

我试图将属性从一个bean复制到另一个bean。 这是两个bean的签名: SearchContent : public class SearchContent implements Serializable { private static final long serialVersionUID = -4500094586165758427L; private Integer id; private String docName; private String docType; private String docTitle; private String docAuthor; private String securityGroup; private String docAccount; private Integer revLabel; private String profile; private LabelValueBean workflowStage; private Date createDate; private Date inDate; private String […]

递归BeanUtils.describe()

是否有一个版本的BeanUtils.describe(客户)以’customer’的复杂属性递归调用describe()方法。 class Customer { String id; Address address; } 在这里,我想使用describe方法来检索address属性的内容。 目前,我所有人都可以看到该类的名称如下: {id=123, address=com.test.entities.Address@2a340e}

BeanUtils将java.util.Map转换为嵌套bean

我有一个Java bean,它有一个字段,而这个字段又是另一个bean public class BeanOne { private String fieldOne; private BeanTwo fieldTwo; public String getFieldOne() {return this.fieldOne;} public void setFieldOne(String fieldOne){this.fieldOne = fieldOne} public BeanTwo getFieldTwo() {return this.fieldTwo;} public void setFieldTwo(BeanTwo fieldTwo){this.fieldTwo = fieldTwo} } public class BeanTwo { private String fieldOne; public String getFieldOne() {return this.fieldOne;} public void setFieldOne(String fieldOne){this.fieldOne = fieldOne} } 我正在尝试将映射传递给BeanUtils以尝试将以下映射转换为BeanOne […]