package com.izouma.jiashanxia.converter;

import com.alibaba.fastjson.JSON;
import com.izouma.jiashanxia.domain.Specification;
import org.apache.commons.lang3.StringUtils;

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

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

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