[jira] [Commented] (BEANUTILS-524) Make BeanUtils copyProperties able to copy Immutable, Mutable and Mixed Java Bean

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[jira] [Commented] (BEANUTILS-524) Make BeanUtils copyProperties able to copy Immutable, Mutable and Mixed Java Bean

ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/BEANUTILS-524?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16986906#comment-16986906 ]

Fabio Borriello commented on BEANUTILS-524:

[~melloware] sounds good! but, with this approach, the common bean util will still have the BULL dependency right?
If I understood well the CopyUtilsBean will be something like:

package org.apache.commons.beanutils2;

import com.hotels.beans.BeanUtils;
import com.hotels.beans.transformer.BeanTransformer;
import com.hotels.transformer.error.InvalidBeanException;

 * ....
public class CopyUtilsBean {
    private final BeanTransformer beanTransformer;

    public CopyUtilsBean() {
        this.beanTransformer = new BeanUtils().getTransformer();

    public CopyUtilsBean(final BeanTransformer beanTransformer) {
        this.beanTransformer = beanTransformer;

     * <p>Copy property values from the origin bean to the destination bean
     * class for all cases where the property names are the same. For each
     * property, a conversion is attempted as necessary. All combinations of
     * standard JavaBeans and DynaBeans as origin and destination are
     * supported.  Properties that exist in the origin bean, but do not exist
     * in the destination bean (or are read-only in the destination bean) are
     * silently ignored and the default value for that type is set.</p>
     * <p>To define specific mappings please refer to {@link com.hotels.beans.BeanUtils}
     * documentation available see:
     * @see <a href="https://hotelsdotcom.github.io/bull/transformer/bean/samples.html">Bean Transformer documentation</a>
     * </p>
     * @param destClass Destination bean class
     * @param orig Origin bean whose properties are retrieved
     * @throws InvalidBeanException if the destination bean is not valid
    public <T> T copyProperties(final Class<T> destClass, final Object orig) {
        return beanTransformer.transform(orig, destClass);

is this what you mean?

> Make BeanUtils copyProperties able to copy Immutable, Mutable and Mixed Java Bean
> ---------------------------------------------------------------------------------
>                 Key: BEANUTILS-524
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-524
>             Project: Commons BeanUtils
>          Issue Type: New Feature
>          Components: Locale BeanUtils / Converters
>            Reporter: Fabio Borriello
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
> h4. Overview
> the copyProperties method in the BeanUtils class, is able to copy only public properties or the ones with a public setter method.
> it would be really useful if this functionality can be extended in order to copy any kind of Java Bean: Mutable, Immutable, Mixed.
> h4. Solution
> Evaluate  the possibility to use, behind the scenes, an open source library that is able to copy Mutable, Immutable and Mixed Java Bean. The library In object is [BULL|https://github.com/HotelsDotCom/bull].
> This would also make able to copy nested objects.

This message was sent by Atlassian Jira