package com.izouma.wenlvju.converter;

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

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

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

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