Questions tagged [apache-commons-beanutils]

Provides dynamic access to Java Bean object properties (without compiled-in knowledge of the property getter and setter methods to be called)

From Commons BeanUtils

Most Java developers are used to creating Java classes that conform to the JavaBeans naming patterns for property getters and setters. It is natural to then access these methods directly, using calls to the corresponding getXxx and setXxx methods. However, there are some occasions where dynamic access to Java object properties (without compiled-in knowledge of the property getter and setter methods to be called) is needed. Example use cases include:

  1. Building scripting languages that interact with the Java object model (such as the Bean Scripting Framework).
  2. Building template language processors for web presentation and similar uses (such as JSP or Velocity).
  3. Building custom tag libraries for JSP and XSP environments (such as Jakarta Taglibs, Struts, Cocoon).
  4. Consuming XML-based configuration resources (such as Ant build scripts, web application deployment descriptors, Tomcat's server.xml file).

The Java language provides Reflection and Introspection APIs (see the java.lang.reflect and java.beans packages in the JDK Javadocs). However, these APIs can be quite complex to understand and utilize. The BeanUtils component provides easy-to-use wrappers around these capabilities. BeanUtils Core And Modules

225 questions
24
votes
3 answers

BeanUtils.cloneBean() deep copy

If all the objects within the bean implement Serializable interface, will BeanUtils.cloneBean() do a deep copy?
hop
  • 2,518
  • 11
  • 40
  • 56
23
votes
3 answers

How to use BeanUtils.copyProperties?

I am trying to copy properties from one bean to another. Here are the signature of two beans: SearchContent: public class SearchContent implements Serializable { private static final long serialVersionUID = -4500094586165758427L; private…
Tapas Bose
  • 28,796
  • 74
  • 215
  • 331
17
votes
3 answers

Java Beans, BeanUtils, and the Boolean wrapper class

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() { …
15
votes
6 answers

BeanUtils copyProperties API to ignore null and specific propertie

Spring's BeanUtils.copyProperties() provides option to ignore specific properties while copying beans: public static void copyProperties(Object source, Object target, String[] ignoreProperties) throws…
Arun
  • 311
  • 3
  • 7
  • 15
15
votes
3 answers

How to get the list of all attributes of a Java object using BeanUtils introspection?

I have method which gets a POJO as it's parameter. Now I want to programmatically get all the attributes of the POJO (because my code may not know what are all the attributes in it at run time) and need to get the values for the attributes also.…
Veera
  • 32,532
  • 36
  • 98
  • 137
14
votes
3 answers

Recursive BeanUtils.describe()

Is there a version of BeanUtils.describe(customer) that recursively calls the describe() method on the complex attributes of 'customer'. class Customer { String id; Address address; } Here, I would like the describe method to retrieve the…
TheLameProgrammer
  • 4,037
  • 5
  • 19
  • 16
14
votes
5 answers

How to ask BeanUtils to ignore null values

Using Commons beanUtils I would like to know how to ask any converter say the Dateconverter to ignore null values and use null as default. As an example consider a public class, public class X { private Date date1; private String string1; …
Kannan Ekanath
  • 16,759
  • 22
  • 75
  • 101
12
votes
8 answers

BeanUtils copyProperties to copy Arraylist

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",…
Monicka Akilan
  • 1,501
  • 5
  • 19
  • 42
11
votes
0 answers

common-collections 4.1 is causing compilation issue when comparing BeanPredicate with EqualPredicate

After upgrading commons-collection from 3.2.2 to 4.1, I am having issues with comparing collections for BeanPredicate and EqualsPredicate. BeanPredicate is from commons-beanutils jar and EqualsPredicate is from commons-collection.jar. BeanPredicate…
Pradeep
  • 1,947
  • 3
  • 22
  • 45
10
votes
1 answer

How to check if bean property exist win BeanUtils or similar?

Is there ready made routine to check if bean has getter for specific property name given by string?
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
10
votes
3 answers

BeanUtils not works for chain setter

e.g. class tester { @Test public void testBeanUtils() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { Stranger stranger = new Stranger(); BeanUtils.setProperty(stranger,"name","wener"); …
wener
  • 7,191
  • 6
  • 54
  • 78
10
votes
4 answers

Setting field value to null with reflection

I am setting a variable value to null, but having problem with it: public class BestObject { private Timestamp deliveryDate; public void setDeliveryDate(Timestamp deliveryDate) { this.deliveryDate = deliveryDate; …
Jaanus
  • 16,161
  • 49
  • 147
  • 202
10
votes
8 answers

Java Collections.sort - help me remove the unchecked warning

List questions = new ArrayList(); questions.addAll(getAllQuestions()); //returns a set of Questions Collections.sort(questions, new BeanComparator("questionId")); //org.apache.commons.beanutils.BeanComparator Under Java 1.5, the…
emulcahy
  • 1,055
  • 3
  • 18
  • 28
9
votes
2 answers

Are there Android compatible alternatives to Property Utils?

Is there a handy-dandy equivalent to org.apache.commons.beanutils.PropertyUtils on Android? I can't seem to use bean utils in my android app due to some dependencies on PropertyDescriptor,and IndexedPropertyDescriptor. So I'm wondering if there are…
user830914
  • 568
  • 5
  • 9
9
votes
1 answer

Copy property with different names between beans using BeanUtils

I would like to copy the property values from Class A to Class B with BeanUtils which has same fields but with different names. Is it possible to provide a map of property name to differentName, age to differentAge etc., and achieve the copying? I…
Cid
  • 1,453
  • 1
  • 18
  • 37
1
2 3
14 15