package com.izouma.jiashanxia.converter;

import com.alibaba.fastjson.JSON;
import com.izouma.jiashanxia.dto.Event;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.AttributeConverter;

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

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