package com.izouma.nineth.converter;


import com.alibaba.fastjson.JSON;
import com.izouma.nineth.dto.CoordinateDTO;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter
public class CoordinateConverter implements AttributeConverter<CoordinateDTO, String> {

    @Override
    public String convertToDatabaseColumn(CoordinateDTO fileObject) {
        if (fileObject != null)
            return JSON.toJSONString(fileObject);
        return null;
    }

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

