package com.izouma.wenlvju.converter;

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

import javax.persistence.AttributeConverter;

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

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