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;

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

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