package com.izouma.wenlvju.converter;

import com.alibaba.fastjson.JSON;
import com.izouma.wenlvju.dto.PerformanceEnquiry;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.AttributeConverter;
import java.util.List;

public class PerformanceEnquiryListConverter implements AttributeConverter<List<PerformanceEnquiry>, String> {
    @Override
    public String convertToDatabaseColumn(List<PerformanceEnquiry> list) {
        if (list != null)
            return JSON.toJSONString(list);
        return null;
    }

    @Override
    public List<PerformanceEnquiry> convertToEntityAttribute(String s) {
        if (StringUtils.isNotEmpty(s)) {
            return JSON.parseArray(s, PerformanceEnquiry.class);
        }
        return null;
    }
}
