apache-commons-beanutils

BeanUtils copyProperties to copy Arraylist

半世苍凉 提交于 2020-01-01 09:22:13
问题 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

How to set date type values using Apache Commons BeanUtils,

梦想的初衷 提交于 2019-12-25 00:36:08
问题 I have an Html form with enctype="multipart/form-data" . I have an dto class it has all setter and getters . Since I am submitting form as multipart, getParameter() method will not work,to process html form fields I used Apache Commons BeanUtils. My servlet is as follow, List<FileItem> items = (List<FileItem>) new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : items) { if (item.isFormField()) { // Process regular form field (input type="text|radio

When can PropertyUtils.copyProperties fail silently?

爷,独闯天下 提交于 2019-12-23 16:21:31
问题 I'm using PropertyUtils.copyProperties() to copy an object's properties via reflection, and it used to work well. Recently however, it started not doing anything. It doesn't throw an exception, but just will not copy any fields. All the fields of the target object remains null, although there are non-null fields in the source objects. I don't know how to reproduce this. For me, it happens consistently, but it's inside a project that I can't just publish here. The project uses Play Framework,

Retrieve field values using BeanUtils

会有一股神秘感。 提交于 2019-12-23 12:13:08
问题 I want to extract private field values that are not marked by certain custom annotation, is this possible via BeanUtils? If yes, how? 回答1: Yes, assuming that you know the fields names. You can use PropertyUtils.getSimpleProperty(...). See also here for an example. 回答2: No, it is not possible with BeanUtils. But you can use Java's own reflection tools like this: public class BeanUtilTest { public static void main(String[] args) throws ... { MyBean bean = new MyBean(); Field field = bean

Java: Merge 2 “beans” to produce a new one

与世无争的帅哥 提交于 2019-12-23 03:24:10
问题 I need to take all the fields and collections from Bean1 and Bean2, sometimes apply some business logic, and produce Bean3 (all beans are hibernate/domain objects of the same type with a reasonably complex graph). Any thoughts on how to do this? Done something similar in the past? My ideas: Dozer (http://dozer.sourceforge.net/) BeanUtils (http://commons.apache.org/beanutils/) Handrolled solution A.N.Other cool solution? Any recommendations? 回答1: Dozer is a nice bean mapping tool. However, it

BeanUtils copyProperties API to ignore null and specific propertie

让人想犯罪 __ 提交于 2019-12-21 08:16:31
问题 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);

BeanUtils converting java.util.Map to nested bean

假装没事ソ 提交于 2019-12-18 02:49:46
问题 I have a Java bean which has a field which in turn is another 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

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

五迷三道 提交于 2019-12-17 19:18:59
问题 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. Finally I'll form a string representation of the POJO. I could use ToStringBuilder, but I want build my output string in certain format specific to my requirement. Is it possible to do so in Beanutils !? If yes, any pointers to the method name? If no,

NoSuchMethodException on trying to get Nested bean property

半世苍凉 提交于 2019-12-13 03:39:24
问题 I have a Product class: public class Product { private ProductClass prodClass; public ProductClass getProdClass() { return prodClass; } public void setProdClass(ProductClass prodClass) { this.prodClass = prodClass; } } And another one ProductClass ... public class ProductClass { private String StbFlag; public String getStbFlag() { return StbFlag; } public void setStbFlag(String stbFlag) { StbFlag = stbFlag; } } When I try to get the Property using BeanUtils.getNestedProperty as shown below..

How to use PropertyUtils to get an element from a list inside a map?

為{幸葍}努か 提交于 2019-12-11 04:07:51
问题 I've been trying to use the indexed notation used for getProperty of PropertyUtils to retrieve an element in a list contained as a map value. Here's an example (I'm using a general syntax here): map = {"aList": ["elem1", "elem2", "elem3"]} Let say, I want to get the value "elem2", I'm trying to do it using: PropertyUtils.getProperty(map, "aList[1]"); but it doesn't seem to work. I always get a null value. Is there another way to do this. To be clear, I know I can do a getProperty("aList").get