package com.izouma.zhirongip.converter;

import com.alibaba.fastjson.JSON;
import com.izouma.zhirongip.domain.FileObject;
import org.apache.commons.lang3.StringUtils;

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

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

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