package com.izouma.zhirongip.converter;

import com.alibaba.fastjson.JSONObject;
import com.izouma.zhirongip.domain.resource.NumOfIp;
import org.apache.commons.lang3.StringUtils;

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

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

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