package com.neusoft.smart.pos.framework.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;

import java.util.ArrayList;
import java.util.List;

public class BeanUtil {
    
    public static <T> T parse(Object source, Class<T> target) {
        if (null == source) return null;
        return JSON.parseObject(JSON.toJSONString(source), target, Feature.IgnoreNotMatch);
    }
    
    public static <T> List<T> parseList(List<?> sourceList, Class<T> target) {
        if (null == sourceList) return null;
        List<T> list = new ArrayList<>();
        sourceList.forEach(item -> list.add(BeanUtil.parse(item, target)));
        return list;
    }
}
