package com.izouma.wenlvju.converter;

import com.alibaba.fastjson.JSON;
import com.izouma.wenlvju.domain.VideoObject;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.AttributeConverter;

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

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