package com.izouma.jmrh.converter;

import com.alibaba.fastjson.JSON;
import com.izouma.jmrh.domain.Contact;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.AttributeConverter;

@Slf4j
public class ContactConverter implements AttributeConverter<Contact, String> {
    @Override
    public String convertToDatabaseColumn(Contact contact) {
        if (contact != null) {
            return JSON.toJSONString(contact);
        }
        return null;
    }

    @Override
    public Contact convertToEntityAttribute(String s) {
        try {
            return JSON.parseObject(s, Contact.class);
        } catch (Exception e) {
            log.error("parse json error", e);
        }
        return null;
    }
}
