package com.izouma.jmrh.converter;

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

import javax.persistence.AttributeConverter;

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

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