com.hbc.api.trade.bdata.common.util.BeanUtilsEnhance.java Source code

Java tutorial

Introduction

Here is the source code for com.hbc.api.trade.bdata.common.util.BeanUtilsEnhance.java

Source

/*
 * Copyright (c) 2015-2016, CCLX.COM. All rights reserved.
 * WANDA GROUP PROPRIETARY/CONFIDENTIAL. 
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is private property; you can't redistribute it and/or modify it
 * under the terms of the LICENSE you obtained from
 *
 *    http://www.cclx.com/
 * 
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. 
 *
 * Author: Jongly Ran
 * Revision: 1.0
 */
package com.hbc.api.trade.bdata.common.util;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.ConvertUtilsBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.hbc.api.trade.bdata.common.exception.ParamValidateException;
import com.hbc.api.trade.bdata.common.exception.enums.CommonReturnCodeEnum;

/**
 * @author Jongly Ran
 */
public class BeanUtilsEnhance {
    private final static Logger log = LoggerFactory.getLogger(BeanUtilsEnhance.class);

    /**
     * ?orig??dest<p/>
     * ???Javabyte, shortdestinteger???
     * @param dest
     * @param orig
     */
    public static void copyProperties(Object dest, Object orig) {
        ConvertUtilsBean convertUtil = new ConvertUtilsBean();
        convertUtil.register(false, true, 10);
        BeanUtilsBean beanUtils = new BeanUtilsBean(convertUtil);
        try {
            beanUtils.copyProperties(dest, orig);
        } catch (IllegalAccessException | InvocationTargetException e) {
            log.error("?from:" + JSON.toJSONString(orig) + ", to: "
                    + JSON.toJSONString(dest), e);
            throw new ParamValidateException(CommonReturnCodeEnum.PARAM_ERROR);
        }
    }
}