apache-commons-beanutils

Performance of BeanUtils vs. ReflectionToStringBuilder (for use in Bean classes)

做~自己de王妃 提交于 2019-12-05 06:23:28
I have a large number of Java bean classes in my web application, and I am trying to find a simple way to implement the toString() methods in these beans. The toString() method would be used for logging throughout the application, and should print the attribute-value pairs of all attributes in the bean. I am trying out two alternatives: 1. BeanUtils.describe() (Apache commons-beanutils) 2. ReflectionToStringBuilder.toString() (Apache commons-lang) Since this is a web application expected to have high traffic, the implementation has to be lightweight and should not impact performance. (Memory

how find fields of all member variables contained in java bean

帅比萌擦擦* 提交于 2019-12-04 19:49:26
I want to make a GUI using Java in which a user can select a bean, edit its fields, and then add an instance of the created bean to a queue. My question though is about accessing the fields. I have a class MyCompositeObject that inherits from MyParentObject. The MyParentObject is composed of multiple beans, each being composed of more beans. The class MyCompositeObject is also composed of beans. I want to find all accessible fields from MyCompositeObject. Class MyParentObject { MyObjectOne fieldOne; MyObjectTwo fieldTwo; String name; ... } Class MyCompositeObject extends MyParentObject {

BeanUtils copyProperties to copy Arraylist

匆匆过客 提交于 2019-12-04 05:38:16
I know that BeanUtils can copy a single object to other. Is it possible to copy an arraylist. For example: FromBean fromBean = new FromBean("fromBean", "fromBeanAProp", "fromBeanBProp"); ToBean toBean = new ToBean("toBean", "toBeanBProp", "toBeanCProp"); BeanUtils.copyProperties(toBean, fromBean); How to achieve this? List<FromBean > fromBeanList = new ArrayList<FromBean >(); List<ToBean > toBeanList = new ArrayList<ToBean >(); BeanUtils.copyProperties(toBeanList , fromBeanList ); Its not working for me. Can any one please help me. Thanks in advance. If you have two lists of equals size then

BeanUtils copyProperties API to ignore null and specific propertie

自古美人都是妖i 提交于 2019-12-04 01:24:28
Spring's BeanUtils.copyProperties() provides option to ignore specific properties while copying beans: public static void copyProperties(Object source, Object target, String[] ignoreProperties) throws BeansException Does the Apache Commons BeanUtils provide a similar feature? Also is it possible to ignore null values while using Spring's BeanUtils.copyProperties() , I see this feature with Commons BeanUtils: Date defaultValue = null; DateConverter converter = new DateConverter(defaultValue); ConvertUtils.register(converter, Date.class); Can I achieve the same with Spring's BeanUtils? edu If

BeanUtils not works for chain setter

自作多情 提交于 2019-12-04 00:55:33
问题 e.g. class tester { @Test public void testBeanUtils() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { Stranger stranger = new Stranger(); BeanUtils.setProperty(stranger,"name","wener"); BeanUtils.setProperty(stranger,"xname","xwener"); BeanUtils.setProperty(stranger,"yname","ywener"); System.out.println(stranger); } @Data// lombok annotation generate all setter and getter public static class Stranger { @Accessors(chain = true)// generate chained setter String

BeanUtils.cloneBean() deep copy

浪尽此生 提交于 2019-12-03 09:57:04
If all the objects within the bean implement Serializable interface, will BeanUtils.cloneBean() do a deep copy? kosa No, cloneBean() does shallow copy only. If you want deep copy. You may refer this link which has technique to do deep copy. Use SerializationUtils.clone method from the Apache Commons Lang for the deep copy . It copies the entire class hierarchy. SerializationUtils.clone(object); There is also another java library which supports both shallow cloning and deep cloning. It offers deep cloning without the need to implement Serializable. Here 来源: https://stackoverflow.com/questions

Set default value for a field while populating POJO using Bean Utils

让人想犯罪 __ 提交于 2019-12-02 06:47:26
问题 I am trying to populate the fields of a POJO using BeanUtilsBean.populate(object, fieldNameVSfieldValueMap) method. My POJO looks like : class POJO{ Integer intField; Double doubleField String str; } Currently I have a HashMap that contains a map between the field name and field value. Now with the following code: POJO obj = new POJO(); Map<String,String> map = new HashMap<>(); map.put("intField", "1"); map.put("doubleField", "1.1"); BeanUtilsBean.populate(obj, map) With the above code in my

Set default value for a field while populating POJO using Bean Utils

天涯浪子 提交于 2019-12-02 05:59:20
I am trying to populate the fields of a POJO using BeanUtilsBean.populate(object, fieldNameVSfieldValueMap) method. My POJO looks like : class POJO{ Integer intField; Double doubleField String str; } Currently I have a HashMap that contains a map between the field name and field value. Now with the following code: POJO obj = new POJO(); Map<String,String> map = new HashMap<>(); map.put("intField", "1"); map.put("doubleField", "1.1"); BeanUtilsBean.populate(obj, map) With the above code in my POJO object obj, the fields intField and doubleField get populated with the values 1 and 1.1

BeanUtils not works for chain setter

一笑奈何 提交于 2019-12-01 03:57:56
e.g. class tester { @Test public void testBeanUtils() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { Stranger stranger = new Stranger(); BeanUtils.setProperty(stranger,"name","wener"); BeanUtils.setProperty(stranger,"xname","xwener"); BeanUtils.setProperty(stranger,"yname","ywener"); System.out.println(stranger); } @Data// lombok annotation generate all setter and getter public static class Stranger { @Accessors(chain = true)// generate chained setter String name; String xname; String yname; public Stranger setYname(String yname)// no lombok, still not work {

Java Beans, BeanUtils, and the Boolean wrapper class

只谈情不闲聊 提交于 2019-11-30 17:37:17
I'm using BeanUtils to manipulate Java objects created via JAXB, and I've run into an interesting issue. Sometimes, JAXB will create a Java object like this: public class Bean { protected Boolean happy; public Boolean isHappy() { return happy; } public void setHappy(Boolean happy) { this.happy = happy; } } The following code works just fine: Bean bean = new Bean(); BeanUtils.setProperty(bean, "happy", true); However, attempting to get the happy property like so: Bean bean = new Bean(); BeanUtils.getProperty(bean, "happy"); Results in this exception: Exception in thread "main" java.lang