package cn.ey.biz.module.system.convert.engagement.business;

import cn.ey.biz.module.system.controller.engagement.business.vo.EngagementBusinessConditionVO;
import cn.ey.biz.module.system.controller.engagement.business.vo.EngagementBusinessCreateRespVO;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class BusinessFieldConverter {

    public static String listToJson(List<EngagementBusinessConditionVO> list) {
        if (CollectionUtil.isNotEmpty(list) || (null != list && list.size() == 0)) {
            return JSONArray.toJSONString(list);
        }
        return null;
    }

    public static List<EngagementBusinessConditionVO> jsonToList(String json) {
        if (StringUtils.isBlank(json)) return null;
        return JSONArray.parseArray(json, EngagementBusinessConditionVO.class);
    }

    public static EngagementBusinessCreateRespVO stringToJson(String json) {
        if (StringUtils.isBlank(json)) return null;
        return JSON.parseObject(json, EngagementBusinessCreateRespVO.class);
    }
}
